开发者

Custom Redirection if Roles don't match

I have an Action result

[A开发者_Python百科uthorize(Roles = "Administrator,Paidmember")]
public ActionResult ListPhotosbyModel(int? id)
{

}

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.


What you can do is override the Authorize attribute, and return your own ActionResult, when the Role is the wrong one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜