How can I create a “security aware” action link that detects if a user is authorized to click (invoke) the action?
Hide link if user is not allowed to use that action…
Depending from
- web.config (authorization) and
- [Authorize] attributes on actions
PS
I guess it is bad practice to mix those 2 in MVC?
This is some code poached from the MvcSitemap project and modified for my own use. If I remember correctly this code has been modified for MVC2 and some of the functions might have to be back ported to MVC1.
Its not bad practices at all to mix MVC and FormsAuthentication together, MVC’s default authentication methods are build around the existing Asp.net security infrastructure.
Code to determine if user has permissions:
Html Helpers
Warning: This won’t work in MVC 5 because the call to FindAction() never returns an action descriptor
I tried to find the issue and couldn’t and ended up programming a work around. 🙁