404 Error Page in IIS

2

Good afternoon, I've developed a system and I have a logic that does not allow profiles that are not authorized 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: Is there a way to put a custom error page in IIS so that when this happens, show me my custom error page? Because I'm afraid of the security of my application.
If anyone can help, I would be grateful!

    
asked by anonymous 23.06.2014 / 19:38

2 answers

3

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>
    
23.06.2014 / 19:55
1

Hello, how are you?

I know that this question has already been answered but there is a lot more about it since you will not be able to return the 404 error in a satisfactory way.

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

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

This will return both the HTTP status 404 and the original url of the page.

You can see this solution explained in more detail in this article: link

    
23.09.2014 / 17:31