【问题标题】:How do I write a cookie inside a static webmethod如何在静态网络方法中编写 cookie
【发布时间】:2012-12-06 13:31:06
【问题描述】:

我正在使用 John Culviner 的 jquery.filedownload 插件。

为此,我需要编写一个 cookie。如何从静态网络方法中编写 cookie?作为页面。响应是一个实例字段,我无法从静态方法访问它。

【问题讨论】:

    标签: c# asp.net cookies static-methods


    【解决方案1】:

    在您的WebMethod 中使用HttpContext.Current 属性。

    【讨论】:

      【解决方案2】:
      var myCookie = new HttpCookie("CookieName");
      myCookie["key"] = "val";
      
      HttpContext.Current.Response.Cookies.Add(myCookie);
      

      【讨论】:

        【解决方案3】:
        HttpContext.Current.Response.Cookies.Get("CookieName");
        

        【讨论】:

          【解决方案4】:

          使用 ff: 代码:

          HttpCookie objHTTPCk = HttpContext.Current.Request.Cookies.Get("Cookie name");
          

          【讨论】:

            猜你喜欢
            • 2013-03-17
            • 2011-09-05
            • 2019-08-31
            • 2018-05-23
            • 2014-01-23
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多