首页 > 代码库 > WebServices中使用Session

WebServices中使用Session

默认情况下,Asp.net使用cookie来管理会话状态。因此,Asp.net假设客户端存储了会话cookie并将它与每一个请求一并发回给客户端。

 /// <summary>    /// Summary description for WebMethodSession    /// </summary>    [WebService(Namespace = "http://tempuri.org/")]    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]    [System.ComponentModel.ToolboxItem(false)]    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.     // [System.Web.Script.Services.ScriptService]    public class WebMethodSession : System.Web.Services.WebService    {        [WebMethod(EnableSession = true)]        public void SaveInSession(string msg)        {            Session["Msg"] = msg;        }        [WebMethod(EnableSession = false)]        public string GetFromSession()        {            return Session["Msg"].ToString();        }    }

 

WebServices中使用Session