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?

asked Oct 9, 2015 at 9:27
3
  • Shouldn't it be path="/ErrorPages/Error500" Commented Oct 9, 2015 at 9:48
  • Area - ErrorPages, Controller - Error, Action - Error500 Commented Oct 9, 2015 at 9:50
  • add @Response.StatusCode=404 in view Commented Oct 9, 2015 at 10:12

1 Answer 1

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

answered Oct 9, 2015 at 9:49
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, for your response. Working fine

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.