Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ResponseMode="File" not working

I want to add simple html pages as custom errors for IIS. So i add 404.html and 500.html pages to project and add next configuration :

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

Html pages are in Views/Shared folder. But every time when i go to some unexisting path /foo/bar i just get error message The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. which is not mine.

For custom errors for ASP.Net i add next configuration :

<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Home/404">
    <error statusCode="404" redirect="~/Home/404" />
    <error statusCode="500" redirect="~/Home/500" />
</customErrors>

and remove filters.Add(new HandleErrorAttribute()); this line from FilterConfig file.

I found that possible problem in correct path to html pages or change / to \ but noone solution that i found didn't help me.


I use IIS7+

like image 642
demo Avatar asked Jan 29 '26 12:01

demo


1 Answers

Documentation to this setting is clumsy.


If responseMode of httpErrors error element is set to File, path is considered as a file path (use \ to separate directories).


Path needs to be relative to the directory that contains web.config file with this setting.

If html file is in Home directory (site root \Home\404.html) and

  • web.config is in site root, path will be Home\404.html
  • web.config is in site root\Home, path will be 404.html
like image 80
tibx Avatar answered Feb 01 '26 03:02

tibx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!