Example How to use EFRoleProvider and functions

Oct 29, 2011 at 4:48 PM

Hi every one,

Can you helpme with some example how to implement EFRoleProvider.

I read what is the concept of Roles in ASP.NET and how to use, but with your code i can't find how to use the function IsUserInRole.

Nov 2, 2011 at 4:14 PM

After config your web.config.

    <roleManager enabled="true">
        <clear />
        <add name="EFRole" 
             type="OmidID.Web.Security.EFRoleProvider, OmidID.Web.Security.EFMembershipProvider"

and try this code:

System.Web.Security.Roles.IsUserInRole("Omid", "Administrators");
System.Web.Security.Roles.Providers["EFRole"].IsUserInRole("Omid", "Administrators");

Nov 26, 2011 at 6:50 PM

Hi Omidid, thanks for your great contribution with this project. I read all the files comprised in the src folder and realized that your created your own tables with no use of membership provider generated by asp.net. I would like to know if all the built-in action filters provided by ASP.NET MVC will work using your solution eg: The [Authorize] Filter like [Authorize(Users="bob,bill")] . Brgds, Sebastian.

Jan 30, 2012 at 11:21 AM

Yes filter (Authorize) will work, and no matter what kind of database you using.
Also in new version you can use Asp.Net database if you like or current database or your custom database...

Feb 3, 2012 at 4:22 PM

thank you omid, i will try it. I checked differences between version 0.9 and 2.0. You are using mapper to work with version 2.0, if using edmx files database first it will impact in any way or mapper is totally separated from the approach - code first or database first - . brgds!

Feb 4, 2012 at 10:32 AM

Yes I used mapper, you can use your custom mapper as you wish, but AutoMapper is automatically set and using Expression to set/get data from model. by the way I convert project to Code First and I have to use mapper but in connection string you can set your Custom EDMX and use your custom User Class Entity type in EFMembership config section like this:

YourUserKeyType can be: System.Int32, System.Int64, System.Guid,..........

OmidID.Web.Security.EFMembershipProvider`2[[MyApp.Models.User, MyApp], [YourUserKeyType]]
Feb 4, 2012 at 2:56 PM

great! thank you for the information.. I will try the proposed solution. Brgds!

Feb 4, 2012 at 10:51 PM

Hi OmidId, probably you could shed some light. a few months ago I asked at asp forums (question http://forums.asp.net/t/1739632.aspx/1?Best+MVC+Starter+Kit+  ) if someone knew a complete starter kit to avoid coding the most obvious in an new mvc project.

by complete starter kit I suggested:

ACL: users, roles, password retrieval, email confirmation of account, openid integration to log with facebook, twitter, and more...

Localization, internationalization: content in different languages through database.

Pagination: a simple integrated pagination extension to start with.

Base Context class: based on the previous functionalities described, a base context defining typical request (like httpcontext.current) but for user name, user country, user language, and then currency of choice, etc...

admin manager: for users, roles, passwords, etc.

Honestly i didnt find any solution comprising those functionalities. Some starter kits at asp.net use membership and profiles from regsql.exe setup but not developed so much - eg, password retrieval not part of the implementation - .  many of those starter kits where in a very early stage...

I was confused about it because many other frameworks - php, ruby on rails, etc - offer such of those functionalities by default or included in apps with BSD license as an example. Do you know if I´m missing something and probably is available or if any open source - with bsd license or similar copyleft - is available out there comprising this basic needs...

brgds, thanks! and sorry in advance for this off topic question...