设置session

来源:互联网 发布:英国读高中知乎 编辑:程序博客网 时间:2024/06/07 08:56
C#代码 
  1. 在asp.net的web服务后台代码  
C#代码 
  1. /// <summary>  
  2. /// 设置Session  
  3. /// </summary>  
  4. /// <param name="name"></param>  
  5. /// <returns></returns>  
  6. [WebMethod(EnableSession = true)]  
  7. public static bool setSession(string name)  
  8. {  
  9.     HttpContext.Current.Session["name"] = System.Web.HttpUtility.UrlDecode(name);  
  10.     return true;  
  11. }  
  12.   
  13. /// <summary>  
  14. /// 获取session  
  15. /// </summary>  
  16. /// <returns></returns>  
  17. [WebMethod(EnableSession = true)]  
  18. public static string getSession()  
  19. {  
  20.     return HttpContext.Current.Session["name"].ToString();  
  21. }