Problem with configuring customErrors ASP.NET MVC 4

0

I need to set up a generic error page for my site, I have added the following code in web config:

<system.web>
  <trust level="Full" />
  <customErrors mode="On" defaultRedirect="~/Views/Error/index.cshtml">
    <error redirect="~/Views/Error/index.cshtml" statusCode="500" />
  </customErrors>
</system.web>

I created the Controller:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SiteTeste.Controllers
{
    public class ErrorController : Controller
    {

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

    }
}

I created the View:

@{
  ViewBag.Title = "Index";
  Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="container-fluid">
<div style="margin-top:100px;margin-bottom:100px;" class="col-md-offset-3 col-md-6">
    <h1>Ocorreu um erro durante a requisição.</h1>
    Ocorreu um erro interno, por gentileza repita o processo ou @Html.ActionLink("Entre em contato","ContactUs","Home") caso o erro persista.
  </div>
</div>

But when an error occurs what appears to me is the message:

  

Error.

     

An error occurred while processing your request.

    
asked by anonymous 21.08.2018 / 16:49

1 answer

0

In your default template, mvc will redirect the error to ~\Views\Shared\Error.cshml . You can simply replace that view with yours and you will not have to worry about it anymore.

If you look at the Application_Start() method you will see that there is a line calling

FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 

That in turn registers the filter

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
  filters.Add(new HandleErrorAttribute());
}

If you want a differentiated treatment you can implement your own handler with the treatments and directions that you consider pertinent.

    
21.08.2018 / 18:15