zoukankan      html  css  js  c++  java
  • 如何在 AjaxPro.net的AjaxMethod中使用session和cookie(转)

    添加一个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);


  • 相关阅读:
    CISCO一些基本配置
    每日学习
    每日学习(个人作业2)
    每日学习
    团队冲刺第十四天
    每日学习
    团队冲刺第十三天
    每日学习
    团队冲刺第十二天
    2021.5.26
  • 原文地址:https://www.cnblogs.com/quanhai/p/1687903.html
Copyright © 2011-2022 走看看