Using the Sample Windows Azure ASP.NET Providers

Previously, the sample Windows Azure ASP.NET providers were included in the samples folder that was installed with the SDK.

As of the November 2009 release of the Windows Azure Tools & SDK, this is no longer the case.  The samples are available online at http://code.msdn.microsoft.com/windowsazuresamples.

To use these samples:

1. Download the samples and unzip (These are no longer included as part of the samples installed to the SDK folder)

2. Add the AspProviders/Lib/AspProviders.csproj project to the solution by right clicking on the solution and selecting Add | Existing Project… and navigating to the AspProviders.csproj file.

3. Add a reference from your ASP.NET MVC 2 Web role to the AspProviders sample library by right clicking on the “references” folder in the ASP.NET MVC project and selecting “Add Reference…”

image

and selecting the AspProviders assembly:

image

4. Open the web.config file and add/change the providers. 

You can set the applicationName appropriately for your application. 

These sections are added under the system.web element. Note that I'm still tracking down some issues I'm seeing with the profile provider, will update this post when I know more.

Membership Provider:

     <membership defaultProvider="TableStorageMembershipProvider" userIsOnlineTimeWindow = "20">
      <providers>
        <clear/>

        <add name="TableStorageMembershipProvider"
             type="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageMembershipProvider"
             description="Membership provider using table storage"
             applicationName="AspProvidersDemo"
             enablePasswordRetrieval="false"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             minRequiredPasswordLength="1"
             minRequiredNonalphanumericCharacters="0"
             requiresUniqueEmail="true"
             passwordFormat="Hashed"
                />

      </providers>
    </membership>

Role Manager Provider:

   <roleManager enabled="true" defaultProvider="TableStorageRoleProvider" cacheRolesInCookie="true" cookieName=".ASPXROLES" cookieTimeout="30"
                 cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration = "true"
                 cookieProtection="All" >
      <providers>
        <clear/>
        <add name="TableStorageRoleProvider"
             type="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageRoleProvider"
             description="Role provider using table storage"
             applicationName="AspProvidersDemo"
                />
      </providers>
    </roleManager>

Session State Provider:

         <sessionState mode="Custom" customProvider="TableStorageSessionStateProvider">
            <providers>
                <clear />
                <add name="TableStorageSessionStateProvider"
                     type="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageSessionStateProvider"
                     applicationName="AspProvidersDemo"
             />
            </providers>
        </sessionState>

Change the existing appSettings element and the folllowing provider configuration:

   <appSettings>
    <add key = "TableStorageEndpoint" value="http://127.0.0.1:10002/devstoreaccount1"/>
    <add key = "BlobStorageEndpoint" value="http://127.0.0.1:10000/devstoreaccount1"/>
    <add key = "AccountName" value="devstoreaccount1"/>
    <add key = "AccountSharedKey" value="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="/>

    <!-- provider configuration -->
    <!-- When using the local development table storage service only the default values given
     below will work for the tables (Membership, Roles and Sessions) since these are the names
     of the properties on the DataServiceContext class -->
    <add key = "DefaultMembershipTableName" value="Membership"/>
    <add key = "DefaultRoleTableName" value="Roles"/>
    <add key = "DefaultSessionTableName" value="Sessions"/>
    <add key = "DefaultProviderApplicationName" value="ProviderTest"/>
    <add key = "DefaultProfileContainerName"/>
    <add key = "DefaultSessionContainerName"/>
  </appSettings>

You can now remove the “ApplicationServices” connection string as all of the providers that referenced it are gone.

6. Hit F5 to debug the application and your application is now using the sample ASP.NET providers that run against Windows Azure storage!

What’s next?  You can bet that we’ll put some more work into these providers to make them better and potentially even provide them as a real library. 

Stay tuned.