title: Recommended way to handle http errors inside my asp.net mvc 5 web application
body: <p>i need a way to globally handle http errors inside my asp.net mvc web application. i did the following if the call to the action method is Ajax :-</p>
  
  <pre><code>$(document).ready(function () {
      $(document).ajaxError(function (e, xhr, textStatus, errorThrown) {
          if (xhr.status == 401)
              window.location = "/Account/Login";
          else if (xhr.status == 403 || xhr.status == 404)
              alert(xhr.statusText, 'Error');
  
          $(".loadingimage").hide();
      });
  </code></pre>
  
  <p>where my action method looks as follow:-</p>
  
  <pre><code> [CheckUserPermissions(Action = "Edit", Model = "Skill")]
        public async Task&lt;ActionResult&gt; DeleteKBLink(int? skillid,int? linktokbid)
        {
            if (skillid == null || linktokbid==null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
        var linktokb=     await unitofwork.SkillRepository.FindLinkToKB(linktokbid.Value);
        if (linktokb == null)
                {
                    return new HttpStatusCodeResult(404, "The link has already been deleted.");
                }
  </code></pre>
  
  <p>but i am not sure how i can handle the http errors in-case the request is not ajax ? currently i will be redirected to http not found page .. thnaks</p>