Custom errors for Applications folders? (ASP.NET)

Where can I set up custom errors for directories in my application like App_Code, App_Browsers, etc.? I already have customErrors set up in my web.config file and it works as expected. For example,

http://www.mysite.com/bla.aspx > redirects to 404 page

but

http://www.mysite.com/App_Code/ > shows "The system cannot find the file specified."

There is no physical App_Code directory for my site. Is this something I can change in IIS?

+1


source to share


4 answers


Are you trying to download content from a protected folder ... ??

I think you might need to access these folders to get the good errors you are looking for ...

http://www.webdavsystem.com/server/documentation/hosting_iis_asp_net/protected_folders

That being said ... there is a reason these folders are protected.

I would never put anything that I need to IIS to work in protected folders.



But are there any reasons to do something? i broke several rules in my short lifespan :)

UPDATE:

Found this when I tried it locally: http://support.microsoft.com/kb/942047/

It looks like reserved directories are throwing special 404s, you can get IIS to target like 404.8 ... with opening to serve those directories

+1


source


I believe you will need to set error pages in IIS itself, since the requests you are talking about never make it to the ASP.NET application. The reason your first example works is because IIS recognizes the .ASPX extension and redirects it to ASP.NET.



+1


source


One way is to provide a redirect in the global.asax file:

 void Application_Error(object sender, EventArgs e) 
{
    //uncomment this to narrow down 'helpful' microsoft messages
    //HttpRequest request = ((HttpApplication)sender).Context.Request; 


    Exception ex = Server.GetLastError();
    //ErrorManager is a custom error handling module
    ErrorManager.ProcessError(ex);
    Response.Redirect("~/error.aspx?error=" + HttpUtility.UrlEncode(ex.Message), true);
}

      

{On the side of the note, I was getting an exception that I just couldn't track down - it just said "file not found" but didn't say which file was missing. It turned out to be a broken link to an image in the css file - breaking the second line of code helped identify the missing file}

0


source


Add a wildcard mapping in IIS to run ALL requests through ASP.net, then you can use Global.asax to handle the error.

Taken from here :

Follow these steps to create a wildcard script with IIS 6.0:

  • Right click the website and select Properties
  • Select the "Home Directory" tab
  • Click the "Configuration" button
  • Select the "Mappings" tab
  • Click the "Insert" button (see Fig. 4).
  • Paste the path to aspnet_isapi.dll in the Executable box (you can copy this path from the script map for .aspx files)
  • Uncheck "Check if file exists
  • Click OK
0


source







All Articles