Sravanti
Sravanti

Reputation: 1407

With out try catch can we redirect to the error page in asp.net?

With out writing the try catches can we redirect a page to the error page or how to know the errors in that page?

Upvotes: 0

Views: 139

Answers (2)

Ben Narube
Ben Narube

Reputation: 448

Have a look at custom error pages. There are several ways to implement this. You can trap errors on page level or application level.

Heres a link to get you started:

http://aspnetresources.com/articles/CustomErrorPages

Personally I like setting my custom error pages from the web config. Like this:

<customErrors
   mode="RemoteOnly" 
   defaultRedirect="~/MyErrorPage.aspx" 
/>

This way we can set the mode to "RemoteOnly" which will allow local users to see detailed error pages with stack trace info plus compilation details, while your remote users (application end users) with be presented with your user friendly custom error page notifying them that an error has occurred.

Upvotes: 0

Sachin
Sachin

Reputation: 40970

You can use Application_Error handler in Global.asax

void Application_Error(object sender, EventArgs e) 
{ 
   // Code that runs when an unhandled error occurs

   // Get Last Error
   Exception exc = Server.GetLastError();
   // Redirect from here
   Response.Redirect("~/Error.aspx");             
}

Upvotes: 2

Related Questions