use*_*479 6 c# session session-cookies asp.net-core
如https://learn.microsoft.com/en-us/aspnet/core/fundamentals/app-state?view=aspnetcore-3.1#session-state中所述,可以将会话添加到自己的 Web 应用程序中,如下所示在开始.配置服务
\n\n services.AddSession(options =>\n {\n options.IdleTimeout = TimeSpan.FromSeconds(10);\n options.Cookie.HttpOnly = true;\n options.Cookie.IsEssential = true;\n });\nRun Code Online (Sandbox Code Playgroud)\n\n并在 Startup.Configure 中
\n\nApp.UseSession()\nRun Code Online (Sandbox Code Playgroud)\n\n还可以通过身份验证中间件使用没有身份的 cookie 身份验证,如此处所述https://learn.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore-3.1
\n\nservices.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)\n .AddCookie(options =>\n {\n ...\n });\nRun Code Online (Sandbox Code Playgroud)\n\n我的问题是,如果我在 Startup.Configure 中同时使用
\n\nApp.UseSession()\nApp.UseAuthentication()\nRun Code Online (Sandbox Code Playgroud)\n\n将使用哪些 Cookie 设置?services.AddSession 中的 Cookie 设置是否完全无关(因为身份验证中间件也使用会话 Cookie 来跟踪用户,对吧?或者我完全错了)?或者它们只是同时运行的两个不同的会话/服务?
\n\n我知道 Startup.Configure (HTTP 管道)是顺序敏感的,正如我的 Microsoft“将中间件添加到应用程序处理管道是顺序敏感\xe2\x80\x94it 仅影响在管道中注册的下游组件”所述。因此,我的第二个问题是,如果我将 App.UseCookiePolicy(options) 放在上面的前面,它会覆盖设置吗?
\n\nApp.UseCookiePolicy()\nRun Code Online (Sandbox Code Playgroud)\n\n预先感谢您的任何答复!
\n