重定向授权失败的MVC [英] Redirect Authorization failure in mvc
问题描述
我一直在做这项研究2天了,但我似乎无法找到答案。
I have been doing this research for 2 days now, but i cant seem to find the answer.
如何用户重定向到指定的页面
这就是我现在:
How to redirect user to a specific page This is what I have now:
<authentication mode="Forms">
<forms loginUrl="~/Account/Member/LogOn" timeout="2880" />
</authentication>
我想要做的是,如果用户没有通过验证重定向到该网址:〜/客户/会员/登录
但是,如果用户已经验证,但没有授权,我想重定向到该网址:
〜/客户/会员/未经授权
What i want to do is if user isn't authenticated redirect to this url: ~/Account/Member/LogOn" but if the user is already authenticated but not authorized, I want to redirect to this url: ~/Account/Member/Unauthorized"
反正有做到这一点,而无需创建一个自定义的验证属性?
Is there anyway to do this without creating a custom authentication attribute?'
感谢
推荐答案
您可以做一个基本的控制器类并覆盖OnActionExecuting方法,然后继承该控制器。见下面的详细信息参考。
You can make a base controller class and override OnActionExecuting method and then inherit that controller. See following reference for details.
<一个href=\"http://stackoverflow.com/questions/3214774/how-to-redirect-from-onactionexecuting-in-base-controller\">How从OnActionExecuting重定向基地控制器?
这篇关于重定向授权失败的MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!