Surya sasidhar
Surya sasidhar

Reputation: 30343

Global.asax page ? In Asp.net?

In web application [asp.net] shall we write code that can retrive data from datbase or insert something in database. in any event of global.asax. when i am writing code in "Application_BeginRequest" even like :

Session["abc"]= 10; it is throwing exception that session can't declare some thing.Session state is not available in this context.

Upvotes: 0

Views: 262

Answers (2)

Chris
Chris

Reputation: 27627

Assuming I am understanding your question correctly then you are right that you cannot access session in that event. Try instead putting it in Application.AcquireRequestState. This is where ASP.NET sets up session and such like.

What you can use in BeginRequest is the Context which is acceesible in that request if you just need to set up data for just that request.

Upvotes: 1

AlfeG
AlfeG

Reputation: 1473

Oh. You need to read about ASP.NET page cycle

Then You will realize that Session state is not available on BeginRequest

Upvotes: 1

Related Questions