Que*_*eUe 3 .net c# cookies static static-methods
我在静态方法中读取 cookie 时遇到问题。我试过:
static void Method()
{
Page page = HttpContext.Current.Handler as Page;
HttpCookie reader= page.Request.Cookies["myCookie"];
}
Run Code Online (Sandbox Code Playgroud)
但我认为这不起作用。
你有什么想法我该怎么做吗?
小智 5
请在此处阅读 msdn 上有关 asp.net 中 cookie 的文档。 我的猜测是您不需要处理程序来读取 cookie。查看HttpContext.Handler是什么。
我建议你尝试一下:
static void Method()
{
HttpCookie reader = HttpContext.Current.Request.Cookies["myCookie"];
}
Run Code Online (Sandbox Code Playgroud)