我们使用mvc创建了一个网站,其中我有3个控制器:
AccountController
HomeController
ContactController
我们在ActionFilters中编写了自定义授权,我们正在检查会话是否已过期。如果会话过期,我们将重定向到登录页面。这是ActionFilter中的代码:
public override void OnAuthorization(AuthorizationContext filterContext)
{
var user = filterContext.HttpContext.User;
var UserProcesses = HttpContext.Current.Session["UserProcesses"] != null ? ((List<string>)HttpContext.Current.Session["UserProcesses"]) : null;
var currentRequest = filterContext.ActionDescriptor.ActionName.ToLower();
var currentController = filterContext.RouteData.Values["controller"].ToString();
if (!string.IsNullOrEmpty(currentController))
{
switch (currentController.ToLower())
{
case "home":
{
if (UserProcesses == null)
{
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary(
new
{
Controller = "Account",
Action = "Login"
})
);
}
break;
case "contact":
{
if (UserProcesses == null)
{
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary(
new
{
Controller = "Account",
Action = "Login"
})
);
}
break;
}
}
}
这非常有效,即当会话到期并且用户点击网站上的任何链接时,他将被重定向到登录页面,其地址为
http:
但是现在我们想在页面上显示一个弹出窗口(无论用户在哪个页面),它将显示消息“该会话已过期”,在取消该弹出窗口后,用户将被重定向到登录页面。
我无法确定如何从ActionFilter本身调用Jquery弹出窗口。我在网上搜索了许多解决方案,但找不到正确的解决方案。有人建议使用
处理未授权请求
调用Action方法(
Call RedirectToAction from ActionFilter
). 然而,我很困惑是否只使用
处理未授权请求
或同时使用此和
OnAuthorization(启用授权)
在我的代码中。有人能提出解决方案吗?
注:
我有一个通用的视图,我可以在其中保存html,以便在整个网站上使用。