SessionStateModule

They have: 5,633 posts

Joined: Jan 1970

Can anyone tell my why the server insists on telling me it is expecing a "}"?
SessionStateModule.End += new EventHandler(object sender, EventArgs e){};'

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

What language is this? What is the context of that line of code?

They have: 5,633 posts

Joined: Jan 1970

C#/ASP.NET its just inline on a page.

I woul do it in the global.asax But for this case it wont work like that.

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

Looks like you'll have to use global.asax:

Quote: Q: Can I subscribe to SessionStateModule.End event using a non-global.asax handler method?
A: The answer is NO. When SessionStateModule raises the End event, only the method
defined in global.asax will be called.

It's limited this way for a technical safety reason. Suppose asp.net allows a user to use any arbitrary handler to the handle the End event. In the case, users will usually use a page method as a handler. When you pass in that handler during event subscription, that handler (unless it's static) is associated with the HttpApplication instance your request is running on. Please note that HttpApplication instances are recycled to serve other requests. So later on, when the End event gets fired, asp.net will call the handler, and the HttpApplication instance it is associated with is now being used by another request. Such a situation will cause all sorts of problem. So to avoid this danger, in v1 a decision was made to call only the method defined in global.asax. Hope you all can bear with this limitation.

from Understanding session state modes + FAQ at forums.asp.net

They have: 5,633 posts

Joined: Jan 1970

Sad I'm gonna cry.

Thankx....

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.