我想在构造方法中定义一个 cookie 值作为类变量,以使所有方法都可以使用 Cookie。
但我收到一条错误消息,例如,
你调用的对象是空的。
public class OrdersController : Controller
{
string userData;
public orderConroller(){
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Request.Cookies[cookieName];
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
userData = authTicket.UserData;
}
public void a(){
//I need Cookie
}
public void b(){
//I need Cookie
}
public void c(){
//I need Cookie
}
public void d(){
//I need Cookie
}
}
我怎么解决这个问题?@.@
谢谢!