Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Errors Work Locally Not Once Deployed On IIS

I have the following:

Web.config

<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<customErrors mode="On" defaultRedirect="~/Error/ShowError">
  <error redirect="~/Error/ShowError/400" statusCode="400" />
  <error redirect="~/Error/ShowError/401" statusCode="401" />
  <error redirect="~/Error/ShowError/403" statusCode="403" />
  <error redirect="~/Error/ShowError/404" statusCode="404" />
</customErrors>
</system.web>

ErrorController

[AllowAnonymous]
public class ErrorController : Controller
{
    public ViewResult ShowError(int id)
    {
        Response.StatusCode = id;
        switch (id)
        {
            case 400:
                return View("~/Views/Error/400.cshtml");
            case 401:
                return View("~/Views/Error/401.cshtml");
            case 403:
                return View("~/Views/Error/403.cshtml");
            case 404:
                return View("~/Views/Error/404.cshtml");
            default:
                return View("~/Views/Error/404.cshtml");
        }
    }
}

FilterConfig

    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        //filters.Add(new HandleErrorAttribute());
    }

Locally everything works fine, I get a custom error page and am happy, however as soon as I deploy the site to my web server, I no longer get my custom error messages and only the generic:

enter image description here

Do I need to add anything specific for the IIS configuration in my online environment?

I've compared the local Web.config with the deployed Web.config and there isn't anything different (that I can see).

like image 492
user1470994 Avatar asked Dec 01 '25 00:12

user1470994


1 Answers

Your error is overwritten by IIS custom error.

Try:

Response.TrySkipIisCustomErrors = true
like image 144
Khanh TO Avatar answered Dec 03 '25 15:12

Khanh TO



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!