How to configure custom Error 500 page?

Asked

Viewed 150 times

1

Good afternoon, I’m starting to write mistakes.

In my web config is installed as follows:

Error 404

 <customErrors mode="On" defaultRedirect="~/Erro/Error-404.html">
      <error statusCode="404" redirect="~/Erro/Error-404.html" />         
 </customErrors>

Error 403

 <system.webServer>
    <httpErrors errorMode="Custom">
      <remove statusCode="403" />
      <error statusCode="403" path="/Erro/Error-403.html" responseMode="ExecuteURL" />      
    </httpErrors>
  </system.webServer>

And for the error 500 attempts in various ways but did not succeed!

Someone can help me?

  • What happens, it displays the error stack or always redirects to the 404?

  • it appears the standard error message 500

2 answers

2

if you use the customErros You need to do the following:

In the FilterConfig.cs comment on that line //filters.Add(new HandleErrorAttribute());

on the web.config add this:

<customErrors mode="On" defaultRedirect="~/paginadeerror/Error">
    <error redirect="~/paginadeerror/Error/404" statusCode="403" />
    <error redirect="~/paginadeerror/Error/404" statusCode="404" />
    <error redirect="~/paginadeerror/Error/500" statusCode="500" />
</customErrors>

Create the controller and view

public class paginadeerrorController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult Error(int id)
    {
        Response.StatusCode = id;
        return View();
    }
}

and if you want a view per code, you will have to write each Actionresult referring to the code, example:

    public ActionResult Error404()
    {
        return View();
    }

and web will stay:

<error redirect="~/paginadeerror/Error404" statusCode="404" />

0

In his Web.config let the <httpErrors> as follows.

<httpErrors errorMode="Custom" existingResponse="Replace">
  <remove statusCode="500" />
  <remove statusCode="404" />
  <remove statusCode="403" />
  <error statusCode="500" responseMode="ExecuteURL" path="/Error/Index" />
  <error statusCode="404" responseMode="ExecuteURL" path="/Error/NotFound" />
  <error statusCode="403" responseMode="ExecuteURL" path="/Error/AccessDenied" />
</httpErrors>

Change the path for the route of its view error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.