2016-03-04 96 views
0

如何重定向,一旦用户登录并且用户关闭了浏览器或标签而未注销并再次打开浏览器或标签并键入url 4示例:www.anything .com,这里的这个URL是我的主页,意思是我的登录页面,但是当用户在url中键入它时,它必须将该用户重定向到仪表板。目前它不是这样工作的。我还没有尝试过任何方法4,因为它不在我的脑海里。我只是在抢我的头。请帮帮我。我不知道它叫什么。如何根据用户角色重定向到特定的控制器

用户可以重定向到UserController的 管理员可以重定向到AdminController喜欢聪明....

+0

这可以帮助你http://stackoverflow.com/questions/9325497/how-to-keep-the -session活性偶数如果-的浏览器 - 是 - 意外关闭 –

回答

0
 

    public class HomeController: Controller 
    { 
    public ActionResult Index() 
    { 
    if (User.IsInRole("admin")) 
    { 
    // The user is an administrator => redirect him to his own page 
    return RedirectToAction("SomeActionName", "SomeControllerName", new { area = "admin" }); 
    } 

    // the use is either not authenticated or not in the admin role => render some view 
    return View(); 
    } 
    } 

相关问题