Payam Sh
Payam Sh

Reputation: 601

Custom error pages based on path/URL in ASP.NET

I have some pages in /panel/ directory and some in /website/ directory. I need two different 404 pages for these pages based on their path, because these directories have different master pages.

when I use customErrors in web.config file, it redirects all pages to one 404 page so it's useless for me.

How can I handle it? Can I handle it in global.asax or master pages or what?

Thanx in advance.

Upvotes: 0

Views: 1110

Answers (2)

João Silva
João Silva

Reputation: 569

You can either create smaller web.config on those locations with the settings you want to override, or on the root web.config you specify the multiple customErrors settings inside location tags.

You don't need to change any code for this.

Upvotes: 2

Luthervd
Luthervd

Reputation: 1416

You want to handle errors in the Global.asax file:

void Application_Error(object sender, EventArgs e)
 { Exception exc = Server.GetLastError(); 
if (exc is HttpUnhandledException) 
{ // Pass the error on to the error page.
 Server.Transfer("ErrorPage.aspx?handler=Application_Error%20-%20Global.asax", true); } }

Check out this link for more info

Upvotes: 1

Related Questions