【发布时间】:2018-03-29 06:47:10
【问题描述】:
我在 .NET 1.0 中编写我的应用程序,然后将其更新到 2.0 版后,我的会话停止工作。
我在 Startup.cs 中的设置:
services.AddDistributedMemoryCache();
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(15);
options.Cookie.HttpOnly = true;
});
...
app.UseSession();
我在控制器上设置会话:
HttpContext.Session.SetString(SessionKey, data);
之后我重定向到包含 angular 的静态文件:
return Redirect($"~/index.html?test={test}");
该文件位于 wwwroot 文件夹中。
当我使用 Angular 从我的应用中获取数据时:
$http.get(baseUrl + "/Configure/Refresh?test=" + test).then(handleSuccess, handleError("Error getting settings")
我在控制器操作中检查会话:
_logger.LogInformation($"Session: {HttpContext.Session.GetString(SessionKey)}");
它是空白的。我不知道为什么 - 在更新之前,它工作正常。
【问题讨论】:
-
您是否使用开发人员工具(网络选项卡)检查了 cookie?您在第一个请求的响应中收到任何 cookie 吗?浏览器是否在请求中将任何 cookie 发送回 data 方法?
标签: c# .net session asp.net-core