Problem with customErrors configuration ASP.NET MVC 4

Asked

Viewed 79 times

0

I need to set up a generic error page for my site, added the following code in the 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 happens what appears to me is the message:

Error.

An error occurred while Processing your request.

inserir a descrição da imagem aqui

1 answer

0

In your default template, mvc will redirect the error to ~\Views\Shared\Error.cshml. You can simply replace this view with your own and no longer need to worry about it.

If you look at the method Application_Start() you’ll see there’s a line calling

FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 

Which 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 you find pertinent.

  • Now I understood where this page came from, but did not solve the problem, how to change this page. :/

  • You edited the ~\Views\Shared\Error.cshml or failed to redirect to your?

  • I created a View Error

Browser other questions tagged

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