What’s the data source Asp.net MVC uses to see if the user is in which role. And how can i change it so that it works with my own database table (when i write [Autorize(Roles="admin")] it checks in the table if the user is in the role )
What’s the data source Asp.net MVC uses to see if the user is in
Share
It uses the
RoleProviderthat is configured in your web.config. If you want to use custom tables you could write acustom role providerby inheriting from theRoleProviderclass and implementing the abstract members. TheIsUserInRolemethod is the one that you should always implement because that’s what will be used in this case:Then you could register your custom role provider in web.config in order to replace the default one:
And if you don’t want to be using any providers (judging from your
previous questionthat seems to be the case) then you should write a customAuthorizeattribute which is not using a role provider at all but is using some custom code of yours:and finally decorate your controller action with this custom attribute instead of relying on the default one which is based on the role provider: