Can I use the ASP.NET Session [] variable in an external DLL

I have two projects - a DLL project in which there is all my logical and data for accessing data, and an ASP.NET project that executes my forms, etc.

I am a bit confused. I thought that if I add the System.Web namespace reference to the DLL project, I could reference the session state information on the ASP.NET page.

I could use every page to get session information and pass it to the DLL for processing, but I would like to be able to process things directly from the DLL class (s).

Is it possible?

I was looking for the System.Web namespace and just can get a reference to the Session variable.

Thanks to everyone.

John

+5
source share
5 answers

You should be able to use HttpContext.Current.Session

Edit

While yes, I agree that you should not tightly couple your DAL business logic, etc. with assemblers ASP.Net. There are many valid cases for accessing the HTTP context outside the web project.

Web controls are perhaps one of the best examples, reusable http modules, etc. etc.

, , DLL , - . , , IStorage, , . SessionStorage MemoryStorage IoC . , , . , , , , .

+10

, .

.

+11

HttpContext.Current.Session DLL, . , , DLL . , , , DLL ASP.NET, .

+2

, HttpContext.Current.Session DLL, , BAL, . , DLL Windows , HTTPContext? , , get, HttpContext.Current.Session catch try , - , db.

+2

HttpContext.Current.Session, dll -. , Windows, Console itc.

It is better to use a method that actively takes a parameter that will be formed from the session value if you are using an ASP.Net application, otherwise there will be no application dependency. If the dll project is already developed and you are trying to change the existing business logic, then no, do not change your exsiting method, use the overload method.

+1
source

All Articles