我在asp.net Web服务的会话概念中有问题,如何在应用程序中实现?
并且我在asp.net中的eval有问题,实际上eval是什么用途
<asp:ImageButton ID="imgbtnDelete" ImageUrl="~/cpanel/images/icons/table/actions-delete.png"
runat="server" CommandArgument='<%#Eval("JobID")%>' OnClick="imgbtnDelete_Click">
答案 0 :(得分:1)
Web服务通常在Web应用程序中运行,就像网站一样,因此您可以访问所有相同的会话功能。
您可以使用以下方式在会话中存储数据:
Session["FirstName"] = "Peter";
Session["LastName"] = "Parker";
使用以下方式进行检索:
ArrayList stockPicks = (ArrayList)Session["StockPicks"];
答案 1 :(得分:1)
public class MyDemo : System.Web.Services.WebService
{
[WebMethod (EnableSession = true)]
public string HelloWorld()
{
// get the Count out of Session State
int? Count = (int?)Session["Count"];
if (Count == null)
Count = 0;
// increment and store the count
Count++;
Session["Count"] = Count;
return "Hello World - Call Number: " + Count.ToString();
}
}
[WebMethod(EnableSession = true)] - 此属性在Web服务中启用会话
从客户端应用程序开启按钮点击事件,我们必须将其写入访问Web服务
localhost.MyDemo MyService;
// try to get the proxy from Session state
MyService = Session["MyService"] as localhost.MyDemo;
if (MyService == null)
{
// create the proxy
MyService = new localhost.MyDemo();
// create a container for the SessionID cookie
MyService.CookieContainer = new CookieContainer();
// store it in Session for next usage
Session["MyService"] = MyService;
}
// call the Web Service function
Label1.Text += MyService.HelloWorld() + "<br />";
}
输出将是: - Hello World - 电话号码:1 Hello World - 电话号码:2 Hello World - 电话号码:3