Solutions for session and session loss in ASP. NET Web Service

Source: Internet
Author: User

1. For a summary of session loss problems, refer to here

2. When using session in Web servcie, you need to process the web method as follows:

[Webmethod (enablesession =   True )]
Public   Void Usingsession ()
{
Session [
" Name " ] =   " Name " ;
}

 

If enablesession is not added= TrueThe session cannot be used in the Web service.

3. Here we will talk about how to use mode = "StateServer" to solve the session loss problem:

1) first enable the Asp.net state service in the Windows service. This service is set to start manually by default.

2) Make the following configuration in Web. config:

< System. Web >
<! -- Other configuration information -->
< Sessionstate Timeout = "200000" Cookieless = "False" Mode = "StateServer" > </ Sessionstate >
</ System. Web >

 

Set timeout as needed. The key is to configure the cookieless attributes.= "False"Mode= "StateServer", cookieless defaults to false, so this attribute can be removed.

If cookieless is set to true, the URL contains the session ID, for example, http: // localhost: 4555/website/(S (dmb2qpn4m2x3cj55pzwcvh55)/index.html. In this case, the Web service will not be able to use the session normally.

 

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.