1

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?

2
  • To reference the sesssion, just import the namespace: System.Web.SessionState then you can use it in any class. Commented Nov 18, 2013 at 11:21
  • Maybe you mean custom session state provider? Please take a look at this link msdn.microsoft.com/en-us/library/h6bb9cz9(v=vs.85).aspx especially customProvider property. Commented Nov 18, 2013 at 11:21

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

You missed the .Current

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.