如何在ASP.NET mvc中跨多个选项卡管理会话。就像我们说我已经在两个标签页中打开了相同的页面,然后我从一个标签中注销,那么我应该自动被重定向到另一个标签页。ASP.NET中的会话管理mvc
0
A
回答
0
在基本控制器中使用会话和呼叫作为覆盖方法,以便在到期时重定向到登录页面。 下面的CustomPrincipal类文件使用using System.Security.Principal;
。
在一类使用会话的一个例子说SessionPersistor:
public static long UserId
{
get
{
if (HttpContext.Current == null) return 0;
if (HttpContext.Current.Session[userId] != null)
return Convert.ToInt64(GetObjectFromSession(userId));
return 0;
}
set
{
SetItemInSession(value, userId);
}
}
public static object GetObjectFromSession(string key)
{
return HttpContext.Current.Session[key];
}
在基地控制器:
protected override void OnAuthorization(AuthorizationContext filterContext)
{
if (!string.IsNullOrEmpty(SessionPersister.UserName)) { filterContext.HttpContext.User = new CustomPrincipal(new CustomIdentity(SessionPersister.UserFullName)); }
else { InvalidRequest(filterContext, "101", "Access denied.", "Session expired or You dont have access to this page."); }
filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
filterContext.HttpContext.Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
filterContext.HttpContext.Response.Cache.SetNoStore();
filterContext.HttpContext.Response.AppendHeader("prod-tool", "no-cache");
base.OnAuthorization(filterContext);
}
创建CustomPrincipal类:(在使用本例的情况下)
public class CustomPrincipal : IPrincipal
{
public CustomPrincipal(CustomIdentity identity)
{
this.Identity = identity;
}
}
public class CustomIdentity : IIdentity
{
public CustomIdentity(string name)
{
this.Name = name;
}
}
0
使用过滤器进行授权处理 - 全局过滤器。
在配置中,您可以配置登录URL,以便用户在未被授权时应该被重定向到您的页面。
如果您的应用程序打开了第二个浏览器窗口(选项卡),则可以编写一个java脚本函数,它遍历所有子窗口并调用刷新。
如何找到子窗口:How to get the references of all already opened child windows
相关问题
- 1. mvc中的会话管理
- 2. ASP.NET中的会话管理
- 3. 的Spring MVC +会话管理
- 4. Spring MVC中的会话管理
- 5. Asp.Net Sql Server会话管理
- 6. asp.net Nhibernate会话管理
- 7. asp.net Nhibernate会话管理
- 8. ASP.NET会话ID管理
- 9. 如何在Spring中管理会话mvc
- 10. 在ASP.NET MVC中处理会话超时
- 11. 如何在asp.net中处理会话mvc
- 12. ASP.NET MVC会话
- 13. ASP.Net如何处理会话管理?
- 14. 亚马逊ec2上的ASP.NET MVC多实例会话管理
- 15. 在ASP.NET MVC中的会话
- 16. ASP.NET MVC - 管理
- 17. 带变量的ASP.NET会话管理
- 18. 当使用IOC模式时,ASP.Net MVC 3会话管理
- 19. ASP.Net MVC会话状态管理 - 跨站点访问
- 20. Spring 3.1 MVC框架会话管理
- 21. 会话管理
- 22. 会话管理
- 23. 会话管理
- 24. iPhone中的会话管理
- 25. Tomcat中的会话管理
- 26. PhoneGap中的会话管理
- 27. 管理node.js中的会话
- 28. vb.net中的会话管理
- 29. gwt中的会话管理
- 30. WPF中的会话管理
看一看[此帖](https://syfuhs.net/2013/03/24/real-time-user-notification-and-session-管理与信号部分2 /)的一种方法使用SignalR。 – NightOwl888