Home
Manage Your Code
Snippet: Membership & Roles (ASP.NET)
Title: Membership & Roles Language: ASP.NET
Description: Web.Config file changes necessary for adding Membership and Role providers. Views: 346
Author: Andrew Faust Date Added: 10/13/2007
Copy Code  
//Set up connection string

<connectionStrings>	
	<add name="CONNECTION STRING NAME" connectionString="CONNECTION STRING" providerName="System.Data.SqlClient"/>
</connectionStrings>

//Set up forms authentication

<authentication mode="Forms" />
	<authorization>
	<allow users="?" />		  
</authorization>

//Set up the Role Provider
<roleManager enabled="true"
	defaultProvider="SqlRoleProvider"
	cacheRolesInCookie="true"
	cookieName=".COOKIE NAME"
	cookieTimeout="30"
	cookieSlidingExpiration="true"
	cookieProtection="All">
	<providers>
		<add name="SqlRoleProvider"
		type="System.Web.Security.SqlRoleProvider"
		connectionStringName="CONNECTION STRING NAME"
		applicationName="APPLICATION NAME" />
	</providers>
</roleManager>

//Set up the membership provider
<membership defaultProvider="DEFAULT MEMBERSHIP PROVIDER NAME">
	<providers>
		<add name="DEFAULT MEMBERSHIP PROVIDER NAME"
			connectionStringName="CONNECTION STRING NAME"
			applicationName="APPLICATION NAME"
			enablePasswordRetrieval="false"
			enablePasswordReset="true"
			requiresQuestionAndAnswer="false"
			requiresUniqueEmail="true"
			passwordFormat="Hashed"
			minRequiredNonalphanumericCharacters="0"
			minRequiredPasswordLength="5"
			type="System.Web.Security.SqlMembershipProvider"
		/>			 
	</providers>		  
</membership>
Usage
The sections in all uppercase need to be replaced
Notes
Not hard stuff, but I do it infrequently enough that I have to look it up each time.