2

Our company is moving to a C# website based on Ektron. I am only vaguely familiar with C# the language, and I haven't used IIS before.

I'm trying to figure out how to hook in to the exception handling mechanism. I want to make sure that if an exception is thrown and isn't caught, I can dispatch an email and redirect to an error page.

As far as I can tell, the important files are web.config and global.asax. But to my knowledge, all web.config can do is specify a redirect URL (and I wouldn't know how to recover the information in the Exception object that was thrown). And my project doesn't even have a global.asax file. (I'm not sure if I need to create that, or if it is deprecated, or if Ektron handles for me).

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Tac-Tics
  • 1,895
  • 13
  • 19
  • Here are what both of those files do: [web.config](http://msdn.microsoft.com/en-us/library/aa306178.aspx), [global.asax](http://msdn.microsoft.com/en-us/library/1xaas8a2(v=vs.71).aspx). If you want global exception handling, you're probably looking to add an `Application_Error` handler in global.asax (more on this [here](http://msdn.microsoft.com/en-us/library/24395wz3(v=vs.100).aspx)). As an aside, you'll find a haphazard approach to picking up ASP.Net will serve you poorly. Best to get a complete overview out of the way as early as possible. – Asad Saeeduddin Nov 21 '13 at 22:44
  • + as you asked, yes you create the global.asax file if it's not present ( unlike web.config it does not have to be ). And I presume we're talking regular ASP.NET, not ASP.NET MVC type of website – frno Nov 21 '13 at 22:48
  • I know Ektron uses Webforms, not MVC. But do I need to create the global.asax file myself? And if so, where does it go? – Tac-Tics Nov 21 '13 at 22:55
  • if you want to use global.asax's functionality, then you gotta create it. It goes into main website folder. You should be using Visual Studio for that, if so then just right click project > Add > New item and there it should be ... (look for extension name - asax) – frno Nov 22 '13 at 00:23

3 Answers3

2

Use Application_Error in Global.asax

evhen14
  • 1,839
  • 12
  • 16
0

See "ASP.NET Health Monitoring Overview". With nothing more than configuration, you can arrange for it to log to the event log, to a database, or wherever.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
0

I'd use ELMAH (Error Logging Modules and Handlers for ASP.NET) to send your e-mails. You can get it via the NuGet Gallery, and all you have to do is add a few lines to your web.config. If you install via NuGet, it even takes care of updating your web.config. Scott Hanselman has a blog post on how to implement it. The post is a little dated (April 2009), but there haven't been many huge changes to ELMAH along the way.

For redirecting to an error page, I'd use the built-in ASP.NET custom error pages.

Brian Oliver
  • 1,407
  • 2
  • 15
  • 25