如何在静态web方法中编写cookie

Mik*_*yev 3 c# asp.net cookies static-methods

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

为了工作,我需要写一个cookie.如何在静态web方法中编写cookie?作为Page.Response是一个实例字段,我无法从静态方法访问它.

Lev*_*lho 7

var myCookie = new HttpCookie("CookieName");
myCookie["key"] = "val";

HttpContext.Current.Response.Cookies.Add(myCookie);
Run Code Online (Sandbox Code Playgroud)


ada*_*ost 5

在中使用HttpContext.Current属性WebMethod