ASP.NET: how can I redirect requests with 404 errors correctly?

I want my ASP.NET MVC application to redirect failed requests to match the action methods of a specific controller. This works fine on my development machine running Windows 7, but not on my operating machine running Windows 2008 R2.

I installed my web.config as follows:

<customErrors mode="On" defaultRedirect="/Error/ServerError/500">       
            <error statusCode="403" redirect="/Error/AccessDenied" />
            <error statusCode="404" redirect="/Error/FileNotFound" />
</customErrors>

This customErrors section works fine on both of my machines (production and development) for 500 internal server errors.

It also works great for 404 errors on my development machine.

However, it incorrectly redirects 404 errors to the production computer. Instead of / Error / FileNotFound, I get a standard 404 page that comes with IIS 7.

What could be the problem?

+3
2

, - : , httpErrors system.webServer:

<httpErrors>
        <remove statusCode="404" subStatusCode="-1" />
        <error statusCode="404" prefixLanguageFilePath="" path="/Error/FileNotFound" responseMode="ExecuteURL" />
</httpErrors>

Windows 2008 R2 IIS (. " " ).

+1

. customErrors httpErrors?

. http://msdn.microsoft.com/en-us/library/ms690576.aspx

customErrors ASP.Net. httpErrors IIS7 ( , ).

, , IIS Pipeline. , IIS Classic Pipeline Mode?

. Integrated Pipeline customErrors .

+1

Source: https://habr.com/ru/post/1737815/


All Articles