gpt4 book ai didi

javascript - 使用 javascript 获取 AspNet.ApplicationCookie

转载 作者:行者123 更新时间:2023-11-28 08:18:14 25 4
gpt4 key购买 nike

我不知道这可能吗,但我必须问一下。有没有办法从 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))
},
});

关于javascript - 使用 javascript 获取 AspNet.ApplicationCookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23336701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com