使用javascript获取AspNet.ApplicationCookie

Get AspNet.ApplicationCookie using javascript

本文关键字:ApplicationCookie AspNet 获取 javascript 使用      更新时间:2023-09-26

我不知道这可能吗,但我必须问。有没有办法从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))                       
    },                
});
相关文章:
  • 没有找到相关文章