6
A
回答
2
根據他們的,你可以設置超時的作用,即
HttpContext.Current.Session.Timeout = 20;
你前面的問題去要動態地做到這一點。您可以在會話中自行存儲和更新時間,併爲基本控制器的每個角色OnActionExecuting
進行設置。
if (User.IsInRole("Admin"))
{
filterContext.HttpContext.Session.Timeout =
(int)filterContext.HttpContext.Session["AdminTimeoutThatYouSetSomewhereElseGlobally"];
}
5
如果您試圖比常規用戶更快地啓動管理員,以下是我在標識中的存根。
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
// other stuff
Provider = new CookieAuthenticationProvider
{
// this function is executed every http request and executed very early in the pipeline
// and here you have access to cookie properties and other low-level stuff.
// makes sense to have the invalidation here
OnValidateIdentity = async context =>
{
// invalidate user cookie if user's security stamp have changed
var invalidateBySecirityStamp = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager));
await invalidateBySecirityStamp.Invoke(context);
// check if user is in admin role
var isAdmin = context.Identity.Claims.Any(c => c.Type == ClaimTypes.Role && c.Value == "AdminRoleName");
// check if enough time has passed to invalidate cookie
var currentUtc = DateTimeOffset.UtcNow;
if (context.Options != null && context.Options.SystemClock != null)
{
currentUtc = context.Options.SystemClock.UtcNow;
}
var issuedUtc = context.Properties.IssuedUtc;
var bootThemOut = (issuedUtc == null);
if (issuedUtc != null)
{
var timeElapsed = currentUtc.Subtract(issuedUtc.Value);
bootThemOut = timeElapsed > TimeSpan.FromMinutes(3); // invalidate admin cookies in 3 minutes
}
if (isAdmin && bootThemOut)
{
context.RejectIdentity();
context.OwinContext.Authentication.SignOut(context.Options.AuthenticationType);
}
}
}
});
+1
我發現這篇文章給了我更好的理解上面的答案:ASPNET身份Cookie身份驗證超時超時使用標識和MVC5:http:///www.jamessturtevant.com/posts/ASPNET-Identity-Cookie-Authentication-Timeouts/ – sobelito 2016-04-07 07:35:30
相關問題
- 1. MVC 5會話超時
- 2. asp.net mvc會話超時
- 3. ASP.NET MVC 4會話超時
- 4. 在ASP.NET MVC會話超時
- 5. 會話超時後,我們可以保留會話嗎?
- 6. ASP.NET MVC 5會話
- 7. ASP.NET MVC中的會話超時警告
- 8. ASP.Net中的會話超時問題MVC
- 9. 在asp.net中的會話超時mvc
- 10. 是否可以在Asp.net中將會話超時設置爲1分鐘?
- 11. 在asp.net中防止會話超時mvc
- 12. 在ASP.NET MVC中處理會話超時
- 13. 會話超時絕不會在asp.net mvc
- 14. ASP.NET中的會話超時
- 15. Asp.Net MVC是否會在會話超時時自動加載HttpGet動作結果
- 16. mvc會話超時
- 17. ASP.NET MVC會話超時不起作用
- 18. ASP.NET MVC會話狀態超時
- 19. ASP.NET MVC會話超時和TempData
- 20. 我是否可以從發出請求的會話中放棄InProc ASP.NET會話?
- 21. 5分鐘後,MVC 4中的會話超時owin
- 22. 如何增加Asp .Net MVC 5中的會話超時時間?
- 23. ASP.NET - 會話超時
- 24. 會話ASP.NET超時
- 25. 會話超時ASP.Net
- 26. 我們是否可以管理已刪除用戶的會話?
- 27. 我們可以在asp.net MVC的視圖中獲取會話值嗎?
- 28. 我們如何可以閱讀或web.config中使用jQuery獲取會話超時,使我們可以在MVC處理會話到期
- 29. ASp.NET MVC - 是否可以簡化我的架構?
- 30. 當用戶有多個角色時,是否有辦法在asp.NET Core MVC中爲會話的其餘部分選擇一個角色?
它適用於ASP.NET MVC 5和ASP.NET身份嗎? – 2014-10-20 13:54:18
將適用於Mvc5。你如何實現身份?你有一個基地控制器?應該沒問題。您對用戶的支票可能會有所不同,但會話是相同的。 – dove 2014-10-20 13:57:44
只會使用,如果你使用會議,這是不啓用默認情況下,AFAIK – sobelito 2016-04-07 07:43:04