This C# project demonstrates how to create an MVC3 Razor Entity Framework & LINQ Custom Membership Provider with Custom Role Provider. Perhaps you are working with a legacy database or you prefer working with a database that uses numeric identity keys instead of Guids. The example UserProfile table in this project uses an integer UserId as the primary key and various other fields that aren't in the default ASP.NET User table. Use the Log On Link in the project and the Register link to create your own account.
Source Code is here for ShiningStarMVC3WebApplication.zip
The SSS.ShiningStarModel contains the Entity data model. It has been setup to use the ADO.NET Poco Entity Generator by right-clicking the model surface and selecting "Add Code Generation Item." I use this because it supports Compiled Queries, which you may wish to use in the future.
The SSS.MemberProviders project contains our SSSMembershipProvider and SSSRoleProvider classes. This will replace the built-in providers. These allow you to use all .NET functionality with your data model. These providers utilize the Entity model and LINQ commands. Not all methods are implemented in these providers, but the main methods required for the LogOn, Register, and ChangePassword are.
The defaultProviders must be setup in the web.config:
description="Entity Framework MVC3 Custom Membership Provider by
Nannette Thacker http://www.shiningstar.net Shining Star Services LLC"
Also add the role provider to the web.config
connectionStringName="ApplicationServices" applicationName="/" />
<!--<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider"
connectionStringName="ApplicationServices" applicationName="/" />-->
The ShiningStarMVC3Website was created from the MVC3 Razor template. The Account LogOn, Register, and ChangePassword views are according to code generation. The AccountModels.cs is also according to code generation.
A ShiningStarMVC2012_2.sql file is included to generate the demo database and example records for the list values. Be sure to search for 00.00.00.00 and update the IP address in the Web.config and App.Config files to your database IP address.
Please check the References. When a project requires the EntityFramework reference, right click the Reference directory, select Manage NuGet Packages. Do an online search for EntityFramework and click to install it.
The ListSet and ListValue tables contain data that is used to populate comboboxes and lists. In our situation, it contains the possible User Roles. The SSS.GlobalListValues project contains Enumerations from the ListSet and ListValue tables so you can work with the values programmatically.
The SSS.GlobalUtilities project contains a CryptoProvider for hashing the password. In the Web.config, setup a Salt value for your database: <add key="SaltValue" value="*!ShiningStar!*" />. This will work fine for a new database, but if you are trying to connect to a legacy database you will need to incorporate your current method of password hashing / encrypting, etc.
I've also included Menu tables for future development. I may add more screens for CRUD operations on the List and Menu tables in the future. The current project does not support those however.