开发者

Implementing a Custom Error page on an ASP.Net website

开发者 https://www.devze.com 2022-12-18 16:33 出处:网络
I have an ASP.Net website and I want to use a custom error page. I put the following code in my web.config

I have an ASP.Net website and I want to use a custom error page. I put the following code in my web.config

<customErrors mode="On" defaultRedirect="~/error.aspx">
    <error statusCode="404" redirect="~/error.aspx" />
</customErrors>
开发者_Python百科

The problem is when i go to a URL that does not exist is still uses the 404 error page specified in IIS Manager.

Question: How can I make it use the error.aspx page I have created? Why do the settings in IIS Manager override the web.config?


Try this way, almost same.. but that's what I did, and working.

<configuration>
    <system.web>
       <customErrors mode="On" defaultRedirect="apperror.aspx">
          <error statusCode="404" redirect="404.aspx" />
          <error statusCode="500" redirect="500.aspx" />
       </customErrors>
    </system.web>
</configuration> 

or try to change the 404 error page from IIS settings, if required urgently.


There are 2 ways to configure custom error pages for ASP.NET sites:

  1. Internet Information Services (IIS) Manager (the GUI)
  2. web.config file

This article explains how to do each:

  • How To Set Up Custom Error Pages In IIS 7.5 With ASP.NET

The reason your error.aspx page is not displaying might be because you have an error in your web.config. Try this instead:

<configuration>
   <system.web>
      <customErrors defaultRedirect="error.aspx" mode="RemoteOnly">
         <error statusCode="404" redirect="error.aspx"/>
      </customErrors>
   </system.web>
</configuration>

You might need to make sure that Error Pages in IIS Manager - Feature Delegation is set to Read/Write:

Implementing a Custom Error page on an ASP.Net website

Also, this answer may help you configure the web.config file:

  • What is the difference between customErrors and httpErrors?


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

Code above is only for "Page Not Found Error-404" if file extension is known(.html,.aspx etc)

Beside it you also have set Customer Errors for extension not known or not correct as

.aspwx or .vivaldo. You have to add httperrors settings in web.config

<httpErrors  errorMode="Custom"> 
       <error statusCode="404" prefixLanguageFilePath="" path="/404.aspx"         responseMode="Redirect" />
</httpErrors>
<modules runAllManagedModulesForAllRequests="true"/>

it must be inside the <system.webServer> </system.webServer>


<system.webServer>     
<httpErrors errorMode="DetailedLocalOnly">
        <remove statusCode="404" subStatusCode="-1" />
        <error statusCode="404" prefixLanguageFilePath="" path="your page" responseMode="Redirect" />
    </httpErrors>
</system.webServer>


Is it a spelling error in your closing tag ie:

</CustomErrors> instead of </CustomError>?
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号