简体   繁体   中英

asp.net customErrors does not react

I need help with settings. It's never use provided page for error 404.

This is my customErrors web.config block:

<customErrors mode="On" defaultRedirect="/systemerror.aspx">
  <error statusCode="404" redirect="/404.aspx" />
</customErrors>

I have these page created and they works well if I call them by url, but when I write in url non-existent page like: http://www.mysite.com/asdfasdasd I am getting:

Server Error

404 - File or directory not found.

The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

It's not use my custom error page 404.aspx, how can I fix this ?

If you are using IIS 7, try:

Response.TrySkipIisCustomErrors = true; 

Refer:

HttpResponse.TrySkipIisCustomErrors Property :Gets or sets a value that specifies whether IIS 7.0 custom errors are disabled.

You are missing ~

<customErrors mode="On" defaultRedirect="~/systemerror.aspx">
   <error statusCode="404" redirect="~/404.aspx" />
</customErrors>

This should work. Let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM