Cookie problems (trouble three days)

 void the SetCookie public (the userName String, Role String, String cookieValueName)
    {FormsAuthentication.FormsCookieName
        the FormsAuthenticationTicket myTick the FormsAuthenticationTicket new new = (. 1, the userName, System.DateTime.Now.AddMinutes (30), the DateTime.Now, to false, Role);
        String = encryptTick FormsAuthentication.Encrypt (myTick);
        the HttpCookie myCookie the HttpCookie new new = (cookieValueName, encryptTick);
        myCookie.Expires = System.DateTime.Now.AddMinutes (30);
        HttpContext.Current.Response.Cookies.Add (myCookie);
    }
this is my set the cookie approach after landing, had cookieValueName is FormsAuthentication.FormsCookieName alternative, suddenly one day hair always get null value (the current situation is unknown, the problem may be more than one cookie [less like, before the good, suddenly changed])

After that, the direct renamed pass a fixed value "CQSPACE", after the value has been found not, change the wording of the N kinds of Cookie, N kinds of modification methods, also found to be invalid, two days later, a new project, you can get the value found, is their own the value of the project can not, today, several new values, it is found that in addition to the value of cQSPACE can get, is not of value cQSPACE .. sudden inspiration came, was reminded of the value of FromsAuthentication.FormsCookieName also called cqspace (this is not case-sensitive) is

the ultimate solution: the WebConfig's <form name = "cqspace" de ../> the name = "cqspace" can be deleted ..
depressed over the past three days and then finally .. a little better ....

Reproduced in: https: //my.oschina.net/secyaher/blog/274349

Guess you like

Origin blog.csdn.net/weixin_34226706/article/details/91966816