Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 631 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why are there two incompatible session state types in ASP.NET?

#1
I see two means of working with session data in ASP.NET MVC:

* `System.Web.SessionState.HttpSessionState`, available on `HttpApplication`
* `System.Web.HttpSessionStateBase`, available on `Controller`

Data stored in one seems to be available in the other.

Unfortunately the only common ancestor of these two types is `System.Object`, meaning that I can't create reusable utility code for the abstraction of either.

Why is the API this way? Is there an important difference between the two that I am missing?
Reply

#2
In ASP.NET MVC abstractions over the classic HttpContext objects Request, Response, Session were introduced. They represent abstract classes and are exposed all over the MVC framework to hide the underlying context and simplify the unit testing because abstract classes can be mocked.

For example for the session object you have [`HttpSessionStateBase`][1] and its implementation [`HttpSessionStateWrapper`][2].

Here's an example of how to convert between the classic ASP.NET session and the abstraction:

HttpSessionStateBase session = new HttpSessionStateWrapper(HttpContext.Current.Session);

So the `System.Web.SessionState.HttpSessionState` which you are referring to is the underlying session object which existed ever since classic ASP.NET 1.0. In MVC this object is wrapped into a `HttpSessionStateWrapper`. But since ASP.NET MVC is an ASP.NET application you still get the Global.asax in which you have the bare session.

[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through