【问题标题】:Read cookies inside a static method在静态方法中读取 cookie
【发布时间】:2013-11-18 20:58:18
【问题描述】:

我在静态方法中读取 cookie 时遇到问题。 我试过了:

static void Method()
{
    Page page = HttpContext.Current.Handler as Page;
         HttpCookie reader= page.Request.Cookies["myCookie"];
}

但我认为它不起作用。

你有什么想法我该怎么做?

【问题讨论】:

  • 为什么你认为它不起作用?请提供更多详细信息。
  • 也许我犯了一个错误,但我看到这个“cookies reader”无法读取cookies :)
  • 您是否在应用程序中设置了任何 cookie?您只会看到来自当前域的 cookie,而不是存储在浏览器中的其他 cookie。
  • 我当然做了,但我想我必须再检查一次我的代码。

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


【解决方案1】:

请阅读 msdn 上关于 asp.net here. 中的 cookie 的文档 我的猜测是您不需要 Handler 来读取 cookie。看看HttpContext.Handler 是什么。

我建议你试试:

static void Method()
{
    HttpCookie reader = HttpContext.Current.Request.Cookies["myCookie"];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 2012-12-06
    • 1970-01-01
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多