In Asp.Net 2.0, server variables such as Session and Application can already be used in WebMethod.
1. 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" Enable session state for XML Web services methods, enable is true. The default state is false.
The above three methods can all realize the use of Session variables. But be careful:
If the status is set to true, when the client accesses WS, the Session variable does not need to be assigned a value and has a default value.
If the status is set to false, when the client accesses WS, it must first assign a value to the Session variable, otherwise an error will be reported.
2. Application
[WebMethod]
public string Hello3()
{
return "Hello," + Application["user"];
}
When using Application, there is no need to set method tags
http://www.cnblogs.com/heekui/archive/2007/01/10/616513.html