demo
demo

Reputation: 6235

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+

Upvotes: 2

Views: 2142

Answers (2)

tibx
tibx

Reputation: 926

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

Upvotes: 9

Dev Superman
Dev Superman

Reputation: 63

I use this

 <httpErrors errorMode="Custom">
      <remove statusCode="404" />
      <remove statusCode="400" />
      <remove statusCode="401" />
      <error statusCode="404" path="Views\Erro\PaginaNaoEncontrada.html" responseMode="File" />
      <error statusCode="400" path="Views\Erro\RequisicaoInvalida.html" responseMode="File" />
      <error statusCode="401" path="Views\Erro\AcessoNegado.html" responseMode="File" />
    </httpErrors>

Upvotes: 0

Related Questions