Obtain the Session value in the class library.

Source: Internet
Author: User

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
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.