I love AppHarbor. I've been waiting for a year for someone to do "Heroku for .NET", and it's finally here! One of the basic use cases for an ASP.NET MVC web app is membership support. This post will be a very quick walk through on using the default (forms authentication) membership provider for an AppHarbor web app.
Create your AppHarbor Application
Creating an application on AppHarbor is straight-forward:
- Go to your Applications tab.
- Click "Create New".
- Fill in a name like "TestMembership".
- Add a database.
- Choose a MSSQL database with the free 20mb option.
- Call the database something like "membershipdb".
That's all that you need to do in AppHarbor! Leave the tab with your database info open, you'll need that in a minute.
Create your MVC Application
Create your ASP.NET MVC application like you would normally:
- In Visual Studio 2010, File -> New -> Project.
- Create a new ASP.NET MVC 3 Project or MVC 2 if you don't have MVC 3 installed.
- Choose Internet Application so that the membership provider is setup locally.
This is all pretty standard. Now we have to setup the AppHarbor database with the membership table structure.
Configuring and Using your AppHarbor Database
There is a great utility called aspnet_sqlreg.exe. This tool will setup membership support on your MS SQL database automatically:
- Start a Visual Studio command prompt by going to Start -> All Programs -> Visual Studio 2010 -> Visual Studio Tools -> Visual Studio Command Prompt.
- Run the following command, using the your AppHarbor database settings to fill in the values in brackets:
aspnet_regsql.exe -S [Host] -d [Name] -U [Username] -P [Password] -A all
- In your MVC project, open your Web.config file.
- Replace the connectionString for ApplicationServices with the connection string found on your AppHarbor database page.
This will setup all the membership services on your AppHarbor database, including role management, profile support, etc. The link to the MSDN page on the tool has all the flags in case you only want some features.
That's it! You can now push your app to AppHarbor and test out that your membership code works.