0
我的應用程序派生自System.Web.Mvc.Controller基類中有一個基礎控制器類。
在重寫方法「ActionResultExecuting」我有我的業務邏輯,檢查存在的身份驗證cookie。
如果當前請求沒有身份驗證Cookie /滿足我的業務條件,我需要將請求重定向到註銷操作,然後重定向到登錄操作。控制器動作從派生控制器類重定向
請找我的代碼片段
public class MyBaseController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
///... User story 1 - Domain1 Cookie present and Domain2 cookie present - Session ID references match in both the cookies
HttpCookie Domain1Cookie= filterContext.HttpContext.Request.Cookies["dm1"];
HttpCookie Domain2Cookie= filterContext.HttpContext.Request.Cookies["dm2"];
if (Domain1Cookie != null && Domain2Cookie != null)
{
string eacCookieValue = Domain1Cookie.Value;
string enrollmentCookieValue = Domain2Cookie.Value;
if (eacCookieValue.Contains(enrollmentCookieValue))
{
string controllerName = RouteData.Values["Controller"].ToString();
string actionName = RouteData.Values["Action"].ToString();
if (controllerName != "Account" && actionName != "Login")
{
////... This is where i need to put my redirection code... Redirect the User to LogOut Action and then redirect to Login
}
}
}
base.OnActionExecuting(filterContext);
}
}
在此先感謝!