3

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).

5
  • did you enable extension less: svenaelterman.wordpress.com/2011/01/31/… ? Commented Jul 26, 2015 at 2:05
  • try installing: support.microsoft.com/en-us/kb/980368 Commented Jul 26, 2015 at 2:07
  • Thanks for the response Khanh, I've been asured that the update has been installed. Never the less I tried <modules runAllManagedModulesForAllRequests="true" /> with no luck. Commented Jul 26, 2015 at 2:15
  • 1
    try Response.TrySkipIisCustomErrors = true Commented Jul 26, 2015 at 2:24
  • That did the trick =) thank you! Commented Jul 26, 2015 at 2:36

1 Answer 1

5

Your error is overwritten by IIS custom error.

Try:

Response.TrySkipIisCustomErrors = true
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.