Page 126 - DCAP312_WEB_TECHNOLOGIES_II
P. 126

Web Technologies-II



                   Notes         By default, the section looks like this when you create a Web application.
                                          <customErrors mode= “Remote Only” />
                                 This will show a generic page to users. To redirect it to one of your own pages, you would
                                 change it to this:
                                          <customErrors mode= “On” defaultRedirect= “error.htm” />
                                 Now all errors that occur will be brought to the error.htm page.
                                 To handle specific errors, and redirect to the error page for everything else you can specify the
                                 error code you want specially handled like so:
                                          <customErrors mode= “On” defaultRedirect= “error.htm”>
                                           <error statusCode= “500” redirect= “error500.aspx?code=500”/>
                                           <error statusCode= “404” redirect= “filenotfound.aspx”/>
                                           <error statusCode= “403” redirect= “authorizationfailed.aspx”/>
                                         </customErrors>
                                 There is a problem here with this solution. Once the redirect is done, your error information is
                                 no longer available on the redirected page. This is because IIS (via the .net framework) performs
                                 a plain old GET request to the error page and does not do a “Server. Transfer” likes the built-in
                                 IIS error handling does.
                                 The only information available to you at this time is the URL that caused this error to be raised.
                                 This is located on the query string as“aspxerrorpath”: http://localhost/ErrorHandling/error500.
                                 aspx?aspxerrorpath=/ErrorHandling/WebForm1.aspx.  The  only  places  this  information  is
                                 available is the two methods described above.
                                 Another interesting point about the above customErrors element is that you can specify different
                                 error pages for different subdirectories.
                                 For this example, let us say you have a directory named “Customers” off of your root directory
                                 that contains a branding specific for logged in customers but is not in its own application. As
                                 such you want to define a different set of pages for errors. Please note that these pages specified
                                 in the “redirect” attribute are relative to the “Customers” subdirectory and not the root path of
                                 your site. It also included a security rule which says only MYDOMAIN\Customers can access
                                 these files. You can define rules for these errors in the web.config file:
                                           <Configuration>
                                           <system.web>
                                           </system.web>
                                           <!--  Configuration  for  the  “Customers”  subdirectory.
                                           -->
                                           <location path= “Customers”>
                                           <system.web>
                                           <customErrors mode= “On” defaultRedirect= “error.htm”>
                                           <error statusCode= “500” redirect= “CustomerError500.
                                           aspx”/>
                                           <error statusCode= “401”
                                           redirect= “CustomerAccessDenied.aspx”/>
                                           <error statusCode= “404”
                                           redirect= “CustomerPageNotFound.htm”/>
                                           <error statusCode= “403” redirect= “noaccessallowed.
                                           htm”/>
                                           </customErrors>
        120                               LOVELY PROFESSIONAL UNIVERSITY
   121   122   123   124   125   126   127   128   129   130   131