Using Membership and Authorization in ASP.NET MVC 4

With the introduction of .NET 4.5 and MVC 4, some changes to Membership and Authorization came along.

To keep this posting as short as possible, I will just list the findings and refer to some postings I read.

1. Web Site Administration Tool is gone, and there is no replacement for it (weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx).

2. Use WebMatrix.WebData.SimpleMembershipProvider instead of System.Web.Providers.DefaultMembershipProvider in web.config (type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")

3. Use WebMatrix.WebData.SimpleRoleProvider instead of System.Web.Providers.DefaultRoleProvider in web.config (type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")

4. There is no (WebMatrix.WebData.)SimpleProfileProvider.

5. To create the required tables yourself, here is a sample script from http://notebookheavy.com/2012/08/22/mvc-4-authentication/.

CREATE TABLE [dbo].[UserProfile] (
[UserId] INT IDENTITY (1, 1) NOT NULL,
[UserName] NVARCHAR (MAX) NULL,
PRIMARY KEY CLUSTERED ([UserId] ASC)
);
 
CREATE TABLE [dbo].[webpages_Membership] (
[UserId] INT NOT NULL,
[CreateDate] DATETIME NULL,
[ConfirmationToken] NVARCHAR (128) NULL,
[IsConfirmed] BIT DEFAULT ((0)) NULL,
[LastPasswordFailureDate] DATETIME NULL,
[PasswordFailuresSinceLastSuccess] INT DEFAULT ((0)) NOT NULL,
[Password] NVARCHAR (128) NOT NULL,
[PasswordChangedDate] DATETIME NULL,
[PasswordSalt] NVARCHAR (128) NOT NULL,
[PasswordVerificationToken] NVARCHAR (128) NULL,
[PasswordVerificationTokenExpirationDate] DATETIME NULL,
PRIMARY KEY CLUSTERED ([UserId] ASC)
);
 
 
CREATE TABLE [dbo].[webpages_OAuthMembership] (
[Provider] NVARCHAR (30) NOT NULL,
[ProviderUserId] NVARCHAR (100) NOT NULL,
[UserId] INT NOT NULL,
PRIMARY KEY CLUSTERED ([Provider] ASC, [ProviderUserId] ASC)
);
 
CREATE TABLE [dbo].[webpages_Roles] (
[RoleId] INT IDENTITY (1, 1) NOT NULL,
[RoleName] NVARCHAR (256) NOT NULL,
PRIMARY KEY CLUSTERED ([RoleId] ASC),
UNIQUE NONCLUSTERED ([RoleName] ASC)
);
 
CREATE TABLE [dbo].[webpages_UsersInRoles] (
[UserId] INT NOT NULL,
[RoleId] INT NOT NULL,
PRIMARY KEY CLUSTERED ([UserId] ASC, [RoleId] ASC),
CONSTRAINT [fk_UserId] FOREIGN KEY ([UserId]) REFERENCES [dbo].[UserProfile] ([UserId]),
CONSTRAINT [fk_RoleId] FOREIGN KEY ([RoleId]) REFERENCES [dbo].[webpages_Roles] ([RoleId])
);

6. One additional posting about “Using SimpleMembership With ASP.NET WebPages“.