Set the cookie method after login, and set the cookie after login

Source: Internet
Author: User

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 ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.