Cpp Lover

整理知识,记录成长轨迹

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

添加一个AjaxPro.HttpSessionStateRequirement 枚举的值到你的AjaxPro.AjaxMethodAttribute中.
例如:
[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]   
现在你就可以像下面这样存取Session的值了:

HttpContext.Current.Session["SessionName"]="SessionValue";

HttpContext.Current.Session["SessionName"].ToString().
另外一个问题:如何在AjaxMethod中使用Cookie?
答案是不能使用"this"的引用存取cookie ,你必须使用HttpContext.Current
例如:
HttpContext.Current.Request.Cookies[Name].Value.
添加 Cookie

System.Web.HttpCookie newcookie=new HttpCookie("CookieName");
      newcookie.Value = "CookieValue";
      newcookie.Path="/";
      newcookie.Expires = DateTime.Now.AddDays(1);
      HttpContext.Current.Response.AppendCookie(newcookie);

      strResult = HttpContext.Current.Request.Cookies["CookieName"].Value.Trim();

清除 Cookie

System.Web.HttpCookie newcookie=new HttpCookie("CookieName");
    newcookie.Expires = DateTime.Now.AddDays(-1);
    newcookie.Values.Clear();
    HttpContext.Current.Response.Cookies.Add(newcookie);

posted on 2010-03-17 10:36  quanhailee  阅读(227)  评论(0编辑  收藏  举报