Custom error messages problem

Discussion in 'ASP.NET 2.0' started by Dekker, Mar 2, 2007.

  1. Hi all. Sorry for the detailed question...

    I have already read the two knowledgebase articlese (http://kb.discountasp.net/article.aspx?id=10105and http://kb.discountasp.net/article.aspx?id=10104), however they did not solve the actual problem.

    In IIS, the <web.config> file is supposed to be able to define the behaviour for errors, including 404, 500, and others. This <web.config> file can be found in any directory, and it will customize the behaviour based on that file.

    But it seems that here we have a configuration panelto setup our "Default" for non-ASP pages, and it uses our <web.config> file only for files that end in .asp(x).

    That does not seem correct... I have a primary website, and I have a web application in a subdirectory. Both the primary website and the web application have custom error pages. If any type of error is encountered in the web application, I want the user to be directed to the web application's custom error messages. If there is any problem in the primary website, I want the user to be directed to the website's custom error pages. Both application and website have "default" error pages defined.

    If I define a custom error page in the DiscountASP control panel,an error for a non-.ASP(x) file in my webapplication re-directs to the primary website's default error page.

    If I do not define a custom error page in the DiscountASP control panel,an error for a non-.ASP(x) gives the IE default 404 page.

    But in local testing, the correct error pages are returned. What am I doing wrong in my website's configurations?

    Dekker
     
  2. Something I'm doing here that seems to work fine is having my own custom ASP error pages for the CP.


    Then for ASP.NET errors I'm using a custom error section in the web.config


    <customErrors mode="On" defaultRedirect="myerror.aspx">
    <error statusCode="500" redirect="myerror500.aspx?code=500"/>
    <error statusCode="404" redirect="thefilenotfound.aspx"/>
    <error statusCode="403" redirect="theauthorizationfailed.aspx"/>
    </customErrors>
     
  3. Hi Wisemx


    Actually, for asp error messages, my <customErrors> section is working fine... but it is for non-aspx error messages...


    If I do a query for servername.com/myapp/nofile.invalidextension, I get the servername.com's default error page that was defined in the ControlPanel. I should instead be getting the default error page defined in my <customErrors> section of the myapp web application... no?[/quote]
     
  4. ...Not sure but I think the web.config will only get used if the error comes from within the application.
     
  5. What are you using as your webserver on your local? Are you running under IIS or the ASP.NET Development Server? Also, are you running a Web Application Project or a Web Site Project? Also, is your custom page included in the appropriate .NET project file?
     
  6. <sigh> My tests were with the IDE...

    So I quickly setup the same master and sub/application website, and repeated the tests...

    It appears that you are right... The web.config can ONLY handle files with the ASPX extension, not even ASP or HTML.... That kinda sucks.

    Now I guess the only way to handle my desired behaviour is to add a HTTP handler to catch all requests to the server, check their result code. If invalid, send it to the appropriate "default" page... <sigh>

    Thanks for pointing out the flaw in my test scenario!
     
  7. Yep, that new modules feature in IIS7 seems awesome. [​IMG]
     
  8. Bruce

    Bruce DiscountASP.NET Staff

    dekker,

    yes. this is the normal behavior. IIS custom error comes way before ASP.NET and the ASP.NET team later on decide to add its own custom error handling.

    Good news is that the IIS and ASP.NET team at Microsoft have merged and IIS 7.0 will have a unified custom error handling.

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  9. Alternatively, you can setup a wildcard * setting that will point all files of any extension to the asp.net ISAPI. This would allow you to control it with the web.config.



    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     

Share This Page