在使用編寫webservice時
C#
[WebMethod(EnableSession = true)]
public string Login(string name)
{
Context
return name;
}
[WebMethod(EnableSession = true)]
public string GetName()
{
if (Context
return Context
else
return
}
ASP
<form id=
<div>
<asp:TextBox ID=
<asp:Button ID=
Text=
</div>
<div>
<asp:Button ID=
Text=
<asp:Label ID=
</div>
</form>
SessionInWebservice
C#
protected void btnLogin_Click(object sender
{
WebService ws = new WebService();
ws
}
protected void btnGetName_Click(object sender
{
WebService ws = new WebService();
lblName
}
問題似乎到此結束了
但如果我們另外新建一個website
其實不然
C#
private static System
= new System
protected void btnLogin_Click(object sender
{
localhost
ws
ws
}
protected void btnGetName_Click(object sender
{
localhost
ws
lblName
}
請注意
但如果是在不同的頁面中調用該webservice
C#
public class WebService
{
private static System
static WebService
{
cookieContainer = new System
}
public WebService
{
this
}
}
調用的時候也不需要重新給CookieContainer賦值了
C#
protected void btnLogin_Click(object sender
{
WebService
ws
}
protected void btnGetName_Click(object sender
{
WebService
lblName
}
From:http://tw.wingwit.com/Article/program/net/201311/13423.html