1

I have got a problem with my application in asp.net mvc 5. I try to create custom error views. I create it by sites: first site, second site

when application is running like local site, everything works fine, but when i deploy it on the server, custom error pages dont work.

In web config my code looks like:

<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/ErrorPages/Error500.cshtml" >
  <error statusCode="500" redirect="~/ErrorPages/Error500.cshtml"/>
  <error statusCode="404" redirect="~/ErrorPages/Error404.cshtml"/>
</customErrors>

...

<httpErrors errorMode="Custom" existingResponse="Replace">
  <remove statusCode="500"/>
  <error statusCode="500" path="/ErrorPages/Error/Error500" responseMode="ExecuteURL"/>
  <remove statusCode="404"/>
  <error statusCode="404" path="/ErrorPages/Error/Error404" responseMode="ExecuteURL"/>
</httpErrors>

Error Controller:

public ActionResult Error500()
    {
        Response.StatusCode = 500;

        return View();
    }

    public ActionResult Error404()
    {
        Response.StatusCode = 404;

        return View();
    }

and view:

@{
    ViewBag.Title = "Error404";
}

Someone knows what is wrong?

Jerzy Gawor
  • 141
  • 1
  • 11

1 Answers1

1

I'm quite sure the reason it's not working when you're deploying is because you're running different IIS versions.

Have a look at Marco's answer in this thread. I can't explain it better: ASP.NET MVC 404 Error Handling

Community
  • 1
  • 1
Ali Reza Dehdar
  • 1,991
  • 1
  • 15
  • 17