• 如何在 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);


  • 相关阅读:
    Vue中过度动画效果应用
    最小公倍数和最大公约数求解方法
    Vue实现双向绑定的原理以及响应式数据
    Hive SQL语法总结
    java安装配置
    Ubuntu vmware补丁
    centos6 安装tensorflow
    python hive
    python 连接 hive
    ubuntu下python通过cx_Oracle库访问oracle数据库
  • 原文地址:https://www.cnblogs.com/quanhai/p/1687903.html
Copyright © 2020-2023  润新知