自定义重定向如果角色不匹配 [英] Custom Redirection if Roles don't match
本文介绍了自定义重定向如果角色不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个动作的结果。
[Authorize(Roles = "Administrator,Paidmember")]
public ActionResult ListPhotosbyModel(int? id)
{
}
如果他一旦登录的用户没有在角色之一,他重定向到登录屏幕,但我想他们重定向到成功完成后,用户将被添加到 paidmember 付款页面code>。
If the user once he is logged in is not in one of the roles he redirected to login screen but I want them redirected to a payment page where upon successful completion the user is added to paidmember
.
我如何重定向到支付页面不能登录页面如果不能在这些角色中的一个?
How do I redirect to a payment page not the login page if not in one of those roles?
推荐答案
You will need to write a custom authorization attribute like tvanfosson does in his answer Here.
然后,您就可以做这样的事情。
You will then be able to do something like
[MyAuthorize(Roles = "Administrator,Paidmember", ViewName = "paidmember")]
这对我来说是伟大的工作。
This is working great for me.
这篇关于自定义重定向如果角色不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文