Question: Accessing user's roles in razor
I've been using MemFlex with MySQL and haven't had any major issues thus far. I'm using roles to authorize certain users within my app, I'm able to check the user's role on the server side but I wasn't able to do the same on my web pages using razor.
@if(User.IsInRole("Admin")) { @Html.ActionLink("Manage", "Index", "Dashboard") }
The snippet seems to be using the default SQL Server membership provider and not MemFlex. Any guidance on how to hook it up?
Also, I was able to use MemFlex in authorizing users in Web API with a custom authorization filter. I'm not sure if a similar method can be applied to my question.
Hi Cubski:
So sorry for the slow reply.
Yes, you'd have to get an IFlexRoleProvider object into your view, which might not be a great idea.
But, if you can get an IFlexRoleProvider into your controller, you could pass a model with IsAdmin property. Getting an IFlexRoleProvider into the controller is relatively easy with an IoC container.
Hope that makes some sense.
Not at all, thanks for taking the time to reply to my post. That makes sense as I'm currently using the same method right now.
Thank you for sharing this awesome library.