默认情况下,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();
        }
    }

 

相关文章:

  • 2022-01-16
  • 2021-11-04
  • 2022-02-07
  • 2021-06-03
  • 2021-09-14
  • 2022-01-27
  • 2021-12-31
  • 2022-01-19
猜你喜欢
  • 2022-12-23
  • 2021-05-19
  • 2021-10-08
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
相关资源
相似解决方案