How to configure custom Error 500 page?

1

Good afternoon, I'm starting to write errors.

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 500 error attempts in many ways but I did not succeed!

Can anyone help me?

    
asked by anonymous 28.09.2018 / 20:47

2 answers

2

If you use customErros you need to do the following:

No FilterConfig.cs comment on this line //filters.Add(new HandleErrorAttribute());

in 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 the 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 by code, you will have to write each ActionResult for the code, eg:

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

and web will stay:

<error redirect="~/paginadeerror/Error404" statusCode="404" />
    
09.10.2018 / 17:12
0

At your Web.config leave <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 to the path of your% error%.

    
09.10.2018 / 17:05