Tuesday, June 30, 2009

Using multiple applications with ASPNETDB

As a web developer, I have used ASPNETDB several times to manage the membership and role information for my applications. It has been a while since I have done software development in ASP.NET. So when I try things now, I realize there are several small things that I knew at my fingertips back then, come with a little more effort right now. I hooked up a new application to use the ASPNETDB, and tried to create a new login. I got the error that the username already exists.

This was surprising, because it was a new application. I realized that the application was actually pointing to the same instance of ASPNETDB on my DB server. I knew that there was some way of isolating multiple applications in the same membership database. After a bit of research I recalled out to do it:

In the web.config file, look for the following section:

<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ApplicationServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
applicationName="/"
/>
</providers>
</membership>

Change the value of the applicationName attribute inside the providers element to then name of your application, and you are good to go!

No comments: