Using the Forms Authentication Membership Provider on AppHarbor
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.
Conclusion
That's it! You can now push your app to AppHarbor and test out that your membership code works.
May 10th, 2011 - 13:43
Thanks very much for this. worked like a charm!
September 9th, 2011 - 04:28
Awesome! it worked, I just added the “LocalSqlServer” with the appharbor connectionstring to my webconfig.
Thanks really useful.
October 19th, 2011 - 17:10
I’m trying to get my first mvc 3 app up and running on AppHarbor with forms auth. I followed this post and I just keep getting “Sorry, an error occurred while processing your request.” when I submit a new user from the Register form. I pasted in the sql server connection info in web.config, so I don’t get it. I can’t find any logs anywhere either so I have no idea why its failing.