I want to define a cookie value as class variable in constructor method to make all methods are available to use the Cookie.
but I got an error message like,
Object reference not set to an instance of an object.
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
}
}
How can I solve this problem? @.@
Thank you!