I needed to use a custom database for my membership and roles in an ASP.NET service it took me a little while to sort out in the web.config so I thought that I would post my web.config here just in case anyone wants to copy it. just replace the words in square brackets with the correct values.

<?xml version="1.0"?>
<configuration >

<appSettings/ >
<connectionStrings >
<add name="ApplicationConnectionString"
connectionString="[ConnectionString]"
providerName="System.Data.SqlClient" / >
<add name="MembershipConnectionString"
connectionString="[ConnectionString]"
providerName="System.Data.SqlClient" / >
</connectionStrings >

<system.web >

<compilation debug="true" / >

<authentication mode="Forms" / >

<membership defaultProvider="SqlMembershipProvider" >
<providers >
<clear / >
<add name="SqlMembershipProvider"
connectionStringName="MembershipConnectionString"
applicationName="AssetManagement"
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" / >
</providers >
</membership >
<roleManager enabled="true" >
<providers >
<clear / >
<add connectionStringName="MembershipConnectionString"
applicationName="AssetManagement"
name="AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" / >
</providers >
</roleManager >
</system.web >
</configuration >



Oh and to add the tables you need to your database use the following command from the command line replacing the words in square brackets with the correct values;
C:\WINDOWS\Microsoft.NET\Framework\[Framework]\aspnet_regsql.exe –E -S [Server] -d [DatabaseName] -A mr


Here is some more info on aspnet_regsql.exe.

4 comments:

Anonymous said...

Thanks for posting this, saved me a lot of time.

Cheers!

Anonymous said...

Thank you!

Anonymous said...

Perfect stuff.Yo dont know how you saved my day!

Daniel said...

You're awesome. Thanks so much for posting.