ASP.NET Membership System.Web.Providers. Can't log in to my siteon Azure but can locally.

Hi there,
I had an interesting issue last night. I deployed my local Azure emulated MVC 3 role and worker role to my Windows Azure instance. All worked perfectly locally and in particular the logon page I built allows me to log onto the secure area of my MVC 3 site using System.WebProviders (ASP.Membership).
I found an issue when I tried to log onto my remote Azure site using my deployed logon view.
The logon on the server failed and told me my user name or password was wrong.
Ok, so I then pointed my local instance ASP.NET configuration (the built in membership, role etc.. tool for setting up members and roles) at my Azure SQL database and tried to manage my members from there and it worked. 
Even when I changed my local connection string to point to my Azure SQL database and tried logging on, it worked. WEIRD!!! (ie.. local browser, remote Azure database).
So then today I fould this blog: 
and then this one:
The part of the post in particular that caught my attention was this:

I tracked it down, thanks to some info in this article by David Hoerster. The problem is that the default password hashing algorithm on Azure is different from the .NET 4.0 defaults. It is set to SHA1 on Azure, and HMACSHA256 is the new standard setting on 4.0.

The rest of the post is here:
This can be fixed by specifying the hash type explicitly in web.config. If you decide to use a method like HMACSHA256, make sure you also specify a machine key – otherwise you will run into similar problems as the autogenerated machine key will differ from server to server.
The configuration element you need to change is under :
<machineKey decryptionKey="PUT_DECRYPTION_KEY_HERE" 
            validationKey="PUT_VALIDATION_KEY_HERE"            
decryption="AES"            
validation="HMACSHA256" />
You can use this machine key generator to generate random keys in the proper format.
I will go home tonight and try this and update this post in the morning…….time passes…….ok, so went home last night and tried a few things. My password hashing algorithm was different between my local and azure. I just used the Azure machine config setting on my local and it all works fine now. Good times!!!
RuSs

My weekend (I’m a geek) of deploying my new Kite Boarding site to Windows Azure with an Azure SQL database, membership and blob storage

Good Morning,
I just thought I’d post to my blog after a long period of being to lazy to do it and also being too busy at work to get around to it.
I spent part of the weekend deploying my latest side project to Azure. I won’t tell you what it’s all about until I have it all polished and shiny as right now it’s a definite work in progress.
What I have deployed:
  • MVC 3, Html5, Razor website – I’m thinking about moving to MVC 4 as I think the beta just came out.
  • The site runs off Entity Framework 4.3 and I used code first poco classes with DBContext.
  • Users and Roles are managed by  http://nuget.org/packages/System.Web.Providers 
  • My custom data is stored an an Azure Sql relational database 
I posted the following questions on MSDN and have now got the answers I need so i’ll update the questhions with answers. As I was an Azure newbie a 2 weeks ago, these questions now seem a bit lame to me!!

Questions:

  • I have used an Azure SQL relational database for my database. They talk a lot about table storage. I assume I have done the right thing in using a relational database?
    Ok, so this one was easy. Whilst I could probably use table storage to store me data (xxx.table.core.windows.net) I am not ready to ditch my relational database way of thinking. My site will have many tables with relationships so for now I am playing it safe and using SQL Azure. I have, however, used blob storage (xxx.blob.core.windows.net) to store the gallery images I need for my site. So, and I may be wrong here, if I had a list of people whom each had a picture attached to their relational database record, I think I could store the blob Url in a field in their record and, when rendering, iterate the records and retrieve the blob image from my storage account.
  • I have used the http://nuget.org/packages/System.Web.Providers to manage users and roles. Once I deployed to Azure using the same database in my web.release.config for my custom data AND the membership tables it all works great. I can register a new user using the standard MVC 3 register user view and I can see this new user in my Users table inside the asp membership table.
    My question here then: and I have Googled this but cant find it, is how do I manage my users and roles on the azure server as I would when I use the asp.netwebadminfiles/default.aspx in Visual Studio? Do I, and I plan to this anyway down the line, write my own custom membership management code to do this or can I use an instance of asp.netwebadminfiles/default.aspx on the server somewhere?
    I figured this one out too. Although there are ways to use the netwebadminfiles tool to manage users and there is also third party code that can do this for you, ultimately I want to manage these users myself. I will build all my user and role code into the site.
  • When I deployed for the first time it created my web svc role on Azure AND my Sql database mentioned above. Lets say I have the site live for a few months and want to redeploy, will my membership and custom data get wiped out? What if a deploy schema changes to my database, will this be taken care of without affecting my data. I know I can use a one way data sync to get the data onto local but im sure I would not have to worry about this?Not 100% sure on this one but I now know that firstly, I don’t have to redeploy / publish the whole site, storage and database every time I make a change. I can use Visual Studio WebDeploy to push new changes to my site. If I needed to sync data from my local I think I could use the Data Sync in the Azure portal and I assume I could manage my users via SQL mambership stored procs. until I get all my membership screens written.
thanks
RuSs