我正在將 .NET 4 Framework ASP.NET MVC 專案遷移到 .NET Core,并且我有以下控制器方法 (.NET 4):
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")] // Never Cache
public virtual ActionResult Extend()
{
// Re-establish the session timeout
Session.Timeout = Utility.Constants.sessionTimout;
return new EmptyResult();
}
這是我在 .NET Core 中的代碼
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
//[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")] // Never Cache
public virtual ActionResult Extend()
{
// Re-establish the session timeout
// TODO: Need to find out in ASP.NET CORE
//this.HttpContext.SessionSession.Timeout = Utility.Constants.sessionTimout;
return new EmptyResult();
}
我一直在嘗試找出如何Session.Timeout在 .NET Core 中進行操作,但并不幸運。
** 更新 ** 此方法從加載到 IFrame 的外部應用程式重新啟動超時。因此,當用戶在 iFrame 應用程式中時,主 ASP.NET 應用程式根本沒有進行任何互動。這就是為什么我需要從 iFrame 應用程式手動延長會話超時。
有什么線索嗎?
uj5u.com熱心網友回復:
我不熟悉TimeOut.net 核心中可用的屬性。
但是,可以使用這里Session描述的狀態
您可以在設定期間設定超時:
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
呼叫您的Extend操作應該足以重置空閑計時器。
請記住,Session在 .net 核心中訪問狀態是不同的,例如:
HttpContext.Session.SetString("foo", "bar");
string foo = HttpContext.Session.GetString("foo");
通常,即使在 中IFrame,使用與頁面互動也應該足以重置IdleTimeout.
作為@Aria,您甚至可以檢測即將到來的超時并采取相應措施。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/457086.html
