Click here to Skip to main content
15,442,754 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i am beginner in asp.net so kindly guide me in simple and to the point wording. i want to understand the use of global.asax in a website or web application. in which situations it is necessary to use?
Posted
Updated 6-May-13 20:41pm
v4

 
Share this answer
 
Comments
Qadri Jillani 7-May-13 2:52am    
thanx for guideline
KM Perumal 7-May-13 2:58am    
WELCOME
You can use Global.asax in different sitautions for example Application_BeginRequest-Whenever any request come to your website you can write anything common.

Real World Scenario I have faced
I have faced cross domain issue while calling a rest service using jQuery from an html5 application.For handle this i have put some code on Application_BeginRequest of my WCF service application which Execute whenever i try to call the service.
Below are the methods in Global.asax for different purpose.Please go through for more clarity
Methods corresponding to events that fire on each request
Application_BeginRequest() – fired when a request for the web application comes in.
Application_AuthenticateRequest –fired just before the user credentials are authenticated. You can specify your own authentication logic over here.
Application_AuthorizeRequest()– fired on successful authentication of user’s credentials. You can use this method to give authorization rights to user.
Application_ResolveRequestCache() – fired on successful completion of an authorization request.
Application_AcquireRequestState() – fired just before the session state is retrieved for the current request.
Application_PreRequestHandlerExecute() - fired before the page framework begins before executing an event handler to handle the request.
Application_PostRequestHandlerExecute() – fired after HTTP handler has executed the request.
Application_ReleaseRequestState() – fired before current state data kept in the session collection is serialized.
Application_UpdateRequestCache() – fired before information is added to output cache of the page.
Application_EndRequest() – fired at the end of each request
Methods corresponding to events that do not fire on each request
Application_Start() – fired when the first resource is requested from the web server and the web application starts.
Session_Start() – fired when session starts on each new user requesting a page.
Application_Error() – fired when an error occurs.
Session_End() – fired when the session of a user ends.
Application_End() – fired when the web application ends.
Application_Disposed() - fired when the web application is destroyed.


Hope this helps
 
Share this answer
 
Comments
Qadri Jillani 7-May-13 3:12am    
thanx alot jameel moideen it was really a great post especially for me .
Refer following links my friend
http://msdn.microsoft.com/en-us/library/1xaas8a2%28v=vs.71%29.aspx[^]

http://www.dotnetcurry.com/ShowArticle.aspx?ID=126[^]

Using Global.asax you can implement
->URLRewriting
->Task Scheduling
 
Share this answer
 
v3
Comments
Qadri Jillani 7-May-13 3:27am    
thanx for guide line
I am also a new one to programming field, and upto my incomplete knowledge Global.asax is used to manage the project/application's different parts..

for example what will happen on Application Start,
What will be happening on Applicaiton End, what on session start, what on session end and so on...

Sorry if my wordings does not make you clear your concepts. :)
 
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