Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts,
I have some confusion in ASP.NET application.

1)Is it mandatory to add global.asax file in Asp.net website?If is not mandatory then in that case application level event(start and end) fire or not?If fire then where we got the implemention or invoke these methods.

C#
void Application_Start(object sender, EventArgs e)
       {
           // Code that runs on application startup

       }

       void Application_End(object sender, EventArgs e)
       {
           //  Code that runs on application shutdown

       }


2)Suppose you have enable session in web.config and threw out application you have not used session any where so in that case these global.asax event fire or not?

C#
void Session_Start(object sender, EventArgs e)
     {
         // Code that runs when a new session is started

     }

     void Session_End(object sender, EventArgs e)
     {

     }


3)Suppose you have not add global.asax then where we have go the implement or invoke these session event (start and end) in application.


Thanks
Dinesh Sharma

What I have tried:

I have tried to execute website in asp.net without global.asax. But not find the implement ion of application and session level events.
Posted
Updated 16-Jun-16 20:38pm

1 solution

It is not mandatory to include it. But if you need to do some work on app start and other events, you have to include it. The events trigger always at appropriate times, it is just that they use default implementation if you don't change them.

And to change them, you have to have global.asax.

So answers:
1) No, not mandatory. Yes, events fire. You don't invoke them, they are events.
2) There is always a session in ASP.NET app. You don't have to use it, but default events will still fire (and you don't have to do anything with them, just ignore them).
3) If you didn't include global.asax, you don't get to implement the events. Again, these are events, they fire at appropriate times in the application life cycle, you don't invoke them.

That said, you could probably create the class equivalent to global.asax with same functionality, but why bother? Include the file, override the events you need to override and ride into the sunset.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900