使用javascript获取AspNet.ApplicationCookie
Get AspNet.ApplicationCookie using javascript
我不知道这可能吗,但我必须问。有没有办法从Cookie中获取AspNet.ApplicationCookie。
我试过:
`$.cookie('.AspNet.ApplicationCookie');`
`document.cookie;`
document.cookie.AspNet.ApplicationCookie;
希望有人知道:D
您应该能够访问它,但必须在cookie身份验证选项中明确允许它。对我来说,这通常意味着打开App_Start文件夹中的Startup.Auth.cs,并在CookieAuthenticationOptions
对象中将CookieHttpOnly
选项设置为false
。在使用模板的新MVC 5应用程序中,它应该是这样的:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
CookieHttpOnly = false, // this option is necessary to allow JavaScript access
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
},
});
相关文章:
- 没有找到相关文章