NashCoding Yet Another Artificial Intelligence Blog

5Feb/113

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:

  1. Go to your Applications tab.
  2. Click "Create New".
  3. Fill in a name like "TestMembership".
  4. Add a database.
  5. Choose a MSSQL database with the free 20mb option.
  6. 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:

  1. In Visual Studio 2010, File -> New -> Project.
  2. Create a new ASP.NET MVC 3 Project or MVC 2 if you don't have MVC 3 installed.
  3. 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:

  1. Start a Visual Studio command prompt by going to Start -> All Programs -> Visual Studio 2010 -> Visual Studio Tools -> Visual Studio Command Prompt.
  2. 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
  3. In your MVC project, open your Web.config file.
  4. 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.

Comments (3) Trackbacks (0)
  1. Thanks very much for this. worked like a charm!

  2. Awesome! it worked, I just added the “LocalSqlServer” with the appharbor connectionstring to my webconfig.
    Thanks really useful.

  3. 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.


Leave a comment

 

Trackbacks are disabled.