2015-12-06 235 views
1

我的,我想重定向到一个页面中的基本控制器代码块,如果用户的状态是0卡在重定向循环

if (UserService.IsLoggedIn()) 
{ 
    model.IsLoggedIn = true; 
    model.CurrentUser = UserService.GetCurrentUser(); 
    model.UserProfile = svc.GetByUserId(model.CurrentUser.Id); 
    if (model.UserProfile.OnboardStatus == 0) 
    { 
     HttpContext.Response.Redirect("/user/onboard/"+ model.UserProfile.Id); 
    } 
} 

我被困在一个重定向循环,我不确定如何解决它。

+0

此控制器代码与哪个路由关联? –

+0

UserController是否基于基础控制器? – dbugger

回答

0

这是因为您继承UserControllerBaseController

解决方案1 ​​:请勿从BaseController继承UserController

解决方案2

我认为您在BaseController在你的OnActionExecuting这部分代码。

如果是这样,你可以更新你的代码如下。

protected override void OnActionExecuting(ActionExecutingContext filterContext) 
{ 
     if (UserService.IsLoggedIn()) 
     { 
      model.IsLoggedIn = true; 
      model.CurrentUser = UserService.GetCurrentUser(); 
      model.UserProfile = svc.GetByUserId(model.CurrentUser.Id); 
      var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower(); 
      var actionName = filterContext.ActionDescriptor.ActionName.ToLower(); 
      if (controllerName != "user" && actionName != "onboard" && model.UserProfile.OnboardStatus == 0) 
      { 
       HttpContext.Response.Redirect("/user/onboard/"+ model.UserProfile.Id); 
       } 
      } 
}