ASP. NET asynchronous processing 1 (Session processing), asp. netsession

Source: Internet
Author: User

ASP. NET asynchronous processing 1 (Session processing), asp. netsession

Generally, when we use ajax to process user information, the Session value cannot be found. Why?

The so-called page is a processing program, and its implementation is very complicated. It needs to be processed through the asp.net pipeline. Generally, the processing program also needs to filter the MPs event to generate HTML and submit it to the browser, but the general processing program. the ashx page only inherits the IHttpHandler interface and cannot pass sessions. What should I do if I want to intercept the Session object Value of HttpContext context?

Public class CustomerPhoto: IHttpHandler

Solution:

First, the ashx page does not directly inherit from the aspx page. We can directly obtain the Session through the page implementation interface, while the ashx page only inherits the IHttpHandler's Session object to intercept the HttpContext context and must implement the IRequiresSessionState, the using System of the imported program. web. sessionState; Use context. session object. In this way, the Session value is obtained.

Public class CustomerPhoto: IHttpHandler, System. Web. SessionState. IRequiresSessionState

Public void ProcessRequest (HttpContext context) intercepts the session value in the passed context.

Public void SavePic ()
{
HttpContext ctx = HttpContext. Current;

}

Ctx is (the packet of HttpContext and all the data worth in the message, that is, the data transmitted by the client.

 

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.