2015-11-18 34 views
0

我有兩種方法會話過期檢查第一次爲控制器和第二次API控制器...我有一個重定向的問題我嘗試了很多方法,但無法重定向...代碼如下。 。重定向onAction執行中的問題

public override void OnActionExecuting(ActionExecutingContext filterContext) 
    { 
     HttpContext ctx = HttpContext.Current; 
     // check sessions here 

     if (HttpContext.Current.Session[Constants.SessionKeys.UserId] == null) 
     { 
      filterContext.Result = new RedirectToRouteResult(
      new RouteValueDictionary { { "controller", "HomeController" }, { "action", "Redirect" } }); 
      return; 
     } 
     base.OnActionExecuting(filterContext); 
    } 

    public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) 
    { 

     HttpContext ctx = HttpContext.Current; 

     // check sessions here 
     if (HttpContext.Current.Session[Constants.SessionKeys.UserId] == null) 
     { 
      System.Web.Mvc.ActionExecutingContext filtercontext = new System.Web.Mvc.ActionExecutingContext(); 
      filtercontext.Result = new System.Web.Mvc.RedirectResult("http://a830edad9050849NDA3307.sharepoint.com/sites/SPBoxUI"); 
      return; 
     } 
     base.OnActionExecuted(actionExecutedContext); 
    } 

在第一個我有在控制器的動作,也將一個破發點在那裏,但我認爲這是不被called.I正在使用MVC4按預期這兩個不工作...在此先感謝親切的幫助

回答

0

請嘗試如下。這段代碼可能會幫助你。

Response.Redirect(Url.Action("Redirect", "Home"));