Webservices uses Session and Application

Source: Internet
Author: User

In Asp. Net 2.0, server variables such as Session and Application can be used in WebMethod.

I. Session

[WebMethod (EnableSession = true)]
Public string Hello ()
{
Return "Hello," + Session ["user"];
}

[WebMethod (EnableSession = false)]
Public string Hello1 ()
{
Return "Hello," + Session ["user"];
}

[WebMethod]
Public string Hello2 ()
{
Return "Hello," + Session ["user"];
}
"EnableSession" is the session state enabled for the XML Web services method, and "true" is enabled. The default status is false.

The above three methods can be used for Session variables. Note:
If the status is set to true, when the client accesses WS, the Session variable can be not assigned, with the default value.
If the status is set to false, the client must assign values to the Session variable before accessing WS. Otherwise, an error is returned.

II. Application
[WebMethod]
Public string Hello3 ()
{
Return "Hello," + Application ["user"];
}
You do not need to set method labels when using Application.

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.