Custom Error Messages in ASP.NET MVC

Even when you have custom errors mode on,
and Have all the custom error pages setup, like the following..

    <customErrors mode="On" defaultRedirect="~/Error" redirectMode="ResponseRewrite">
      <error statusCode="403" redirect="~/403" />
      <error statusCode="401" redirect="~/401" />
      <error statusCode="404" redirect="~/404" />
      <error statusCode="409" redirect="~/409" />
      <error statusCode="500" redirect="~/500" />

You even set Response.TrySkipIisCustomErrors = true; on your error handler to get rid of those ugly IIS default error pages.
        /// <summary>
        ///     Returns a Not Found error.
        /// </summary> 
        [HttpGet, Route("404")]
        public ActionResult NotFound()
            Log.Error("Not Found - 404 : {0}".FormatWith(HttpContext.Request.RawUrl));
            HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
            HttpContext.Response.TrySkipIisCustomErrors = true;

            return View();

But still, nothing works. Until you set the following config line.

    <httpErrors existingResponse="PassThrough"/>

Popular posts from this blog

Print a sales receipt using a thermal printer with C# for POS Application

Automatic redirect upon session timeout using ASP.NET MVC and Javascript

Could not create SSL/TLS secure channel - Fixed