Sigur
Sigur

Reputation: 317

What .net class to inherit from to use asp.net sessions, but isn't a page

I have a asp.net webapplication in vb.net. Sessions are available on a page that inherits from Inherits System.Web.UI.Page. To have better separation of concerns I'm thinking about creating a class that knows about server sessions, but isn't a page. I could instance the class with a session-object or set a property, but i was wondering if is it possible to create a class that knows about the session. What should the class inherit from?

What would be a different design pattern?

Upvotes: 1

Views: 758

Answers (1)

Peter
Peter

Reputation: 27944

You can just access your session with:

HttpContext.Current.Session

Any class you create as base class can have a property with returns the HttpContext.Session, it is not bound to your Page object.

HttpContext MSDN

Upvotes: 5

Related Questions