title: IIS showing server error instead of custom errors
body: <p>I'm using MVC 5 and I'm handling my errors with a custom views for errors such as (404, 403.. etc)
  It works fine on my local IIS but when I publish on a <strong>staging server</strong> it shows the IIS server error messages regarding these error codes.</p>
  
  <p><strong>It's showing this message:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/e26cW.png" alt="Showing this message"></p>
  
  <p><strong>instead of:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/2PJ8n.png" alt="instead of this"></p>
  
  <p>I have modified the <code>web.config</code> for <code>&lt;customErrors mode="Off" /&gt;</code></p>
  
  <p><strong>Global.asax</strong></p>
  
  <pre><code>        if ((Context.Server.GetLastError() is UnauthorizedAccessException))
          {
              log.LogError(Context.Server.GetLastError().Message, Context.Server.GetLastError());
              customErrorPage = @"~/Error/?id=403"; //security
          }
          else if ((Context.Server.GetLastError() is HttpException) &amp;&amp; (((HttpException)Context.Server.GetLastError()).GetHttpCode() == 404))
          {
              //** Handle 404 error and response code
              log.LogError("404", Context.Server.GetLastError());
              customErrorPage = @"~/Error/?id=404";
          }
          else
          {
              log.LogError(Context.Server.GetLastError().Message, Context.Server.GetLastError());
              customErrorPage = @"~/Error";
          }
  
          if (ConfigurationHelper.Common.ShowCustomErrorPage)
          {
              var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
              Response.Redirect(urlHelper.Content(customErrorPage), false);
              Server.ClearError();
          }
  </code></pre>
  
  <p><strong>Error controller:</strong></p>
  
  <pre><code>    public ActionResult Index(string id)
      {
          if (!string.IsNullOrEmpty(id) &amp;&amp; id.Equals("404"))
          {
              Response.StatusCode = 404;
              return !Request.IsAjaxRequest() ? (ActionResult)View("404") : PartialView("404");
          }
          if (!string.IsNullOrEmpty(id) &amp;&amp; id.ToLower().Equals("403"))
          {
              Response.StatusCode = 403;
              return !Request.IsAjaxRequest() ? (ActionResult)View("Security") : PartialView("Security");
          }
          return !Request.IsAjaxRequest() ? (ActionResult)View("Index") : PartialView("Index");
      }
  </code></pre>
  
  <p>What should I do in-order to show my custom error messages?</p>