从登录页面MVC 4重定向如果认证 [英] MVC 4 Redirect from login page if authenticated
问题描述
通过使用默认的MVC 4 Web应用程序如何可以将用户重定向到某个页面,如果他是在登录?我的意思是,当您试图访问一个页面,装饰有 [授权]
属性,它会将您重定向到登录页面,并在URL参数是你试过页面访问。如果登录成功,您将被重定向到特定页面。现在你验证,您可以访问特定页面。但是,如果你回到登录页面的http://页:端口/帐号/登录
它仍然会显示登录页面。我怎样才能从重定向登录页面的用户,如果他/她已经在loged?
我应该在控制器 GET登录操作使用
从帐户控制?
如果(Request.IsAuthenticated)
{
...重定向到...
}
您可以使用 RedirectToAction
在你的控制器是这样的:
如果(Request.IsAuthenticated)
{
返回RedirectToAction(指数,家);
}
By using a default MVC 4 web application how can I redirect the user to certain page if he is logged in? What I mean when you try to access a page that is decorated with [Authorize]
attribute, it will redirect you to login page and the parameter in the url is the page you tried to access. If login succeeded, you will be redirected to that specific page. Now you are authenticated and you can access that specific page. But if you go back to the login page http://page:port/Account/Login
it will still display the login page. How can I redirect the user from login page if he/she is already loged in?
Should I use this in the controller GET Login action
from Account Controller?
if(Request.IsAuthenticated)
{
...redirect to ...
}
You can use RedirectToAction
in your controller like this:
if(Request.IsAuthenticated)
{
return RedirectToAction("Index","Home");
}
这篇关于从登录页面MVC 4重定向如果认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!