Reputation: 5595
What i would like to do is catch any exception that hasn't been handled in the web application then send the user to a screen saying something like
"Were sorry this has crashed"
And at the same time send the exception to our ticketing systems.
I am assuming I need to put it in the the global.cs somewhere just not sure where?
Upvotes: 0
Views: 814
Reputation: 172825
You can configure a custom error page in the web.config as follows:
<configuration>
<system.web>
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly">
</customErrors>
</system.web>
</configuration>
It is also wise to log those exceptions. There are several populair logging frameworks who can do this for you. Two of them, ELMAH and CuttingEdge.Logging, have standard integration facilities for ASP.NET, which allows to to write no single line of code. Using CuttingEdge.Logging for instance, you can configure your site to automatically log errors to the Windows event log as follows:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging"
type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<logging defaultProvider="WindowsEventLogger">
<providers>
<add name="WindowsEventLogger"
type="CuttingEdge.Logging.WindowsEventLogLoggingProvider, CuttingEdge.Logging"
source="MyWebApplication"
logName="MyWebApplication" />
</providers>
</logging>
<system.web>
<httpModules>
<add name="ExceptionLogger"
type="CuttingEdge.Logging.Web.AspNetExceptionLoggingModule, CuttingEdge.Logging"/>
</httpModules>
</system.web>
</configuration>
Application_Error
as Philip suggests. However, those logging frameworks might have a lot of functionality you might want to consider.
Good luck.
Upvotes: 3
Reputation: 2801
You need the Application_Error
event in Global.cs
protected void Application_Error(object sender, EventArgs e)
{
}
Upvotes: 3