Yesterday, when I was optimizing my website code, I had a sudden whim trying to separate the Page code from the business logic code. That is, the. cs file under the page is only used to collect data on the front-end, and business processing is put in some class libraries. However, the problem is that the Session cannot be directly used in the class library. I searched many websites on the Internet (many of them are the same). I tried them one by one and tried many times, but some of them were quite simple. Based on what you said on the internet, I wrote a Demo as follows:
Reference the System. web namespace in the class library to use the session
Reference the following two namespaces in the Class1 class of the class library.
Using System. Web;
Using System. Web. SessionState;
Use Session in its class
Set the Session on the default page
This is done simply by using Session in the class library. There are still some other methods on the Internet, and some bugs have not been debugged. Haha ......
From persimmon expensive