ASP Website does not seem to use machineKey in Web.Config for FormsAuthentication.Decrypt

江枫思渺然 提交于 2019-12-03 16:40:33

You also asked this at http://forums.asp.net/p/1956219/5581762.aspx. See my answer there:

In the WCF service, set <machineKey ... compatibilityMode="Framework45" />. This will cause it to use the same algorithm as ASP.NET.

(Also remember to change your machine key if you inadvertently copied & pasted your real key into the question above.)

Levi answered my question over here: http://forums.asp.net/t/1956219.aspx.

Adding will infer compatibilityMode="Framework45" to the machineKey section.

So to fix this bug, either add compatibilityMode="Framework45" to the machineKey section or add to the system.web section of your web.config of your ASP website.

I think you should do something like

var authCookie = FormsAuthentication.GetAuthCookie(userName, rememberUser.Checked);
// Get the FormsAuthenticationTicket out of the encrypted cookie
var ticket = FormsAuthentication.Decrypt(authCookie.Value);
// Create a new FormsAuthenticationTicket that includes our custom User Data
var newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, "userData");
// Update the authCookie's Value to use the encrypted version of newTicket
authCookie.Value = FormsAuthentication.Encrypt(newTicket);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!