Owin cookie 未发送

Jim*_*nor 6 c# cookies asp.net-mvc owin

我在使用 OWIN 和 cookie 身份验证时遇到一些问题。需要明确的是,OWIN 生成的 cookie 永远不会发送到浏览器。我知道已经有很多关于这个问题的帖子和答案,但没有一个对我有用。我在本地环境中工作,使用 ASP.NET Framework 4.5.2 和 IIS 10,项目中也使用了会话。ASP.NET_SessionId cookie 存在。

以下是我在身份验证过程中使用的不同文件:

Global.asax 中的 Session_Start

Session["Dummy"] = "0";
Run Code Online (Sandbox Code Playgroud)

Startup.cs中的配置

ConfigureAuth(app);
Run Code Online (Sandbox Code Playgroud)

Startup.Auth.cs中的ConfigureAuth

app.UseKentorOwinCookieSaver(PipelineStage.Authenticate);

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LoginPath = new PathString("/Identification/Index"),
    CookieManager = new SystemWebChunkingCookieManager(),
});
Run Code Online (Sandbox Code Playgroud)

提交表单登录后,我检查帐户是否有效,如果有效,则执行此代码

Claim[] claims = new Claim[]
{
    new Claim(ClaimTypes.Email, cpt.Login), // Email address
    new Claim(ClaimTypes.Name, cpt.Identite.Nom), // User Name
    new Claim(ClaimTypes.NameIdentifier, cpt.NumeroClient.ToString()) // Unique ID of user account
};
ClaimsIdentity userIdentity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
IOwinContext owinContext = Request.GetOwinContext();
IAuthenticationManager owinAuthenticationManager = owinContext.Authentication;

owinAuthenticationManager.SignIn(new AuthenticationProperties() {
    IsPersistent = true,
    AllowRefresh = true,
    ExpiresUtc = DateTime.Now.AddMonths(1)
}, userIdentity);
Run Code Online (Sandbox Code Playgroud)

然后我重定向到主页

return RedirectToAction("Index", "Home");
Run Code Online (Sandbox Code Playgroud)

但我看不到饼干。我尝试添加

<authentication mode="None"></authentication>
Run Code Online (Sandbox Code Playgroud)

在“system.web”下的web.config中,仍然没有任何内容。正如你所看到的,我正在使用 Kendor Cookie Saver,但仍然对我不起作用:( 我尝试在 Startup.Auth.cs 中设置 cookie 的路径、域和安全,还尝试实现我自己的 cookie经理,但什么也没做。

你们能看到我错过的东西吗?谢谢您的帮助。

另外,这是我在 stackoverflow 上的第一篇文章,如果我需要改进它,请告诉我,总会有下一次。

这是吉米

更新

创建新的 MVC 项目时,我遇到了零问题。我可以看到 ApplicationCookie,因此它必须与我正在处理的当前项目(大约 8 年前创建)有关。我尝试更新/添加任何 NuGet 包,因此我的 packages.config 文件看起来像空项目,但仍然什么也没有。我将自己尝试一些东西,所以我至少可以不再使用会话,但无法充分利用 Owin 的身份验证潜力是非常令人沮丧的:(