Let's collect some tips for evaluating the appropriate use of global.asax.
Effectively, global. asax allows you to write code that runs in response to "system level" events, such as the application starting, a session ending, an application error occuring, without having to try and shoe-horn that code into each and every page of your site.
They defined methods for a single class, application class. They are optional, but a web application has no more than one global. asax file.
asax is not required by ASP.NET for a website to run. It is, however, very useful for application-level functionality (like unhandled exception logging). Save this answer.
Setting HandleError Attribute as a Global Filter Any unhandled exception that takes place within the boundary of the MVC application will now be handled by this global error handler. To test this global handler, comment out the [HandleError] attribute from the action or the controller and then run the application.
It's simple to use if your session and application initialization code is very small and application-specific. Using an HttpModule is more useful if you want to reuse code, such as setting up rules for URL rewriting, redirects or auth. An HttpModule can cover everything a Global.asax file can. They can also be removed and added easily using your .config.
I've used it before to catch errors at the application level, and to do something when a user's session expires.
I also tend to use it a lot to provide static properties that read values from the web.config.
I think it ok for stuff like that, though I wouldn't put much more than that in there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With