Set the cookie method after login, and set the cookie after login
public void SetCookie(string userName, string role,string cookieValueName) {FormsAuthentication.FormsCookieName FormsAuthenticationTicket myTick = new FormsAuthenticationTicket(1, userName, System.DateTime.Now.AddMinutes(30),DateTime.Now, false, role); string encryptTick=FormsAuthentication.Encrypt(myTick); HttpCookie myCookie = new HttpCookie(cookieValueName,encryptTick); myCookie.Expires = System.DateTime.Now.AddMinutes(30); HttpContext.Current.Response.Cookies.Add(myCookie); }
This is the method for setting the cookie after I log on. Originally, cookieValueName uses FormsAuthentication. after FormsCookieName is replaced, the null value is always obtained one day. (the current situation is unknown. It may be due to the issue of multiple cookies. [This is not the same as it was before. It suddenly changed])
After that, I directly renamed the fixed value "CQSPACE" and later found that the value was not obtained. I changed N Cookie writing methods and N modification methods. I also found that the modification method was invalid. Two days later, I created a new project, we can find that we can get the value, that is, our project cannot be the value. Today, we have created several new values, and we can find all the values except CQSPACE, that is, we cannot get the value of CQSPACE .. I was inspired by FromsAuthentication. the value of FormsCookieName is also called cqspace (Case Insensitive)
Solution: delete name = "cqspace" in <form name = "cqspace" de ../> of WebConfig ..
The depressing three days have passed. We can have a better time ....