Error page 404 in IIS

Good afternoon, I have developed a system and I have a logic that does not allow profiles that do not have authorization to access parts of the system that are not allowed for it. What happens is that when trying to access an area that is not allowed, IIS gives a 404(Not Found) error page in response to the failed attempt. What I wanted to know is: how do I put a custom error page in IIS, so that when this situation happens, show my error page personalized ? Because I'm afraid about the security of my application.
If anyone can help, I would be grateful !

Author: Érik Thiago, 2014-06-23

2 answers

Tem.

In your Web.config file, add the following:

<system.web>
    <customErrors mode="On" >
        <error statusCode="404" redirect="~/SeuControllerDe404" />
    </customErrors>
</system.web>

Controller:

public class SeuControllerDe404 : Controller 
{
    [AllowAnonymous]
    public ActionResult Index() 
    {
        return View();
    }
}

View:

<div>Oops! Este endereço não existe.</div>
 3
Author: Leonel Sanches da Silva, 2014-06-27 17:41:30

Hello, All right?

I know this question has already been answered but there is much more to it since, in this way, you will not be able to return the Error 404 satisfactorily.

The safest way to do this would be by using <httpErrors> inside <system.webServer>, as in the example below:

<httpErrors errorMode="Custom">
    <remove statusCode="404"/>
    <error statusCode="404" path="/erro404.html" responseMode="File"/>
<httpErrors>

In this way you will return both HTTP status 404 and preserve the original url of the page.

You can see this solution further explained in this article: http://davidsonsousa.net/pt/post/criando-paginas-de-erro-404-personalizadas-no-aspnet-mvc

 1
Author: Davidson Sousa, 2014-09-23 15:31:50