Azure sdk 1.3 and machine key
We recently moved to azure sdk 1.3 and we have the following issue
The machine key in the web.config changes to a different one. This behavior can be observed when we are debugging any azure web role in visual studio. Because of the change in machine key, already existing users do not log on to the system. Only the newly created users log in.
We would like to know how to ensure that the machine key does not change.
Thanks and Regards,
Diwakar
Hi Diwakar,
You have to set the Machine Key explicitly for all instances of your web roles. Checkout this post
Original discovered this via this post.
Thanks SparkCode. I will try the above mentioned and update the post accordingly. But, what is the reason behind automatic changing of machine key? It surprised me why the machine keys for all the roles are changed when the role starts. I couldnt find any documentation for the same.
Regards,
Diwakar
Hi SparkCode,
Unfortuantely, this didnt work. I read the web.config in Application_BeginRequest (to test) and tried to save the configuration and got Access denied exception. The problem started to occur when we moved to azure sdk 1.3. We did not have this problem with azure sdk 1.2. We have already explicitly mentioned the machine key section in the web.config but the runtime writes in the web.config.
Regards,
Diwakar
Hi Diwakar,
That's strange - haven't updated to SDK 1.3 as yet but if you are setting a machine key explicitly in web.config and it is changing on deployment to another key ..... that is not expected behavior ?
i.e. this could be a problem with 1.3 IMHO because it means that cookies cannot be decrypted and encrypted due to the change in the Machine Key. That is - they are potentially encrypted/decrypted with one key and then using another different one. Perhaps SDK 1.3 is ignoring values set in the web.config file and automatically setting a machine key for you ?
Have you tried not setting a machine key at all and seeing if this is now handled automatically? However, if the machine key is changing every time .... yes, that's a significant problem for cookies. Try deploying to Azure and see whether this behavior occurs on the platform or just locally ?
If you have tried all these and nothing is working - then its a problem .... so respond to this thread ?
The problem can be easily reproduced by following the steps below:
- Create a new azure project and add a web role to it
- Open the web.config and add machine key to it. Leave the web.config open
- Debug the project and observe
You will be prompted with a dialog box that web.config is modified and do you want to reload it. If you reload it, the machine key line in the web.config is changed.
If the web.config is marked read-only, the debugger throws an exception and the role will not launch. The problem is reported in the post http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/thread/e7cfbefa-afeb-4b7d-997d-55167936eb7d
I wonder why no body from Microsoft is accepting or denying the issue.
Regards,
Diwakar
We have a habit of deleting the staging environment quickly because of the dumb getting charged even if it is stopped rule so nothing to fall back on right now.
The obvious workaround is to keep a copy of the deployment in Azure Storage where you pay only 15c/GB/month. But, realistically, keeping a stopped single instance in Staging for one day would have cost less than $3.
Until a better way to fix it is provided you can get around the issue by RDP'ing to your instance, take web.config from E:\approot and copy to E:\approot\_WASR_\0
Good thing this didn't happen with 1.2 before we had rdp!
Doesn't this totally hose any site that uses membership providers to encrypt and hash passwords? None of our existing users could log in today and now any newly created accounts will not be able to login, ever. Seems like a pretty big problem!! Frustrating, how could something like this be missed?
Until a better way to fix it is provided you can get around the issue by RDP'ing to your instance, take web.config from E:\approot and copy to E:\approot\_WASR_\0
Good thing this didn't happen with 1.2 before we had rdp!
Doesn't this totally hose any site that uses membership providers to encrypt and hash passwords? None of our existing users could log in today and now any newly created accounts will not be able to login, ever. Seems like a pretty big problem!! Frustrating, how could something like this be missed?
I totally agree with your fustation :|
I made a test and it seems that each instance of the web role change the machine key so that if I have 2 instances, they have 2 different validationkeys... So we loose all benefits of multiple instance ... each postback can potentiall fall into a "viestate
Validation" exception, isn't it ?
The solution of changing the key with RDP doesn't resolve much... if a VM fails, Azure creates a new one with a new machinekey... In this way a simple hosting solution is better and cheeper...
I'm just disintalling SDK 1.3 and returning to 1.2 .... hoping that next realeses will be MUCH better...
That was our thought yesterday too but running the 1.2 installer would fail. The logs showed some error about needing to use the latest sdk version. Not sure if it was connecting out to MS to check the version or if something was just messed up on my system. Let us know if you have more luck.I'm just disintalling SDK 1.3 and returning to 1.2 .... hoping that next realeses will be MUCH better...
I unistalled SDK 1.3 and Tools for VS 1.3 ..
then installed the Tools 1.2 and all was fine..
good luck
A possible workaround to this problem is in WebRole we add a startup task. This task will run in the background and wait to x amount of sec for role to initialize and then copy the Web.config to E:\approot\_WASR_\0 folder.
<Startup>
<Task commandLine="CopyWebConfig.cmd" executionContext="elevated" taskType="background">
</Task>
</Startup>
CopyWebConfig.cmd
@echo off
REM Sleep for 180 sec
ping -n 180 127.0.0.1 > NUL 2>&1
copy E:\approot\web.config E:\approot\_WASR_\0\web.config
Leaf.ly, I didn't think that different instances would get different machineKeys... are you sure about that? (How did you do the test?)Not sure if multiple instances get a different key as we only are running 1 right now. The problem is we have keys specified in the web.config file because they are used in our membership provider to hash the passwords. When we publish, the web.config gets updated to a different value so users logged in see error pages everywhere because the cookies are wrong, existing users can't login because the password can't be verified, and any users that sign up during that time will experience the same issues forever now that we have updated to the correct keys in production.
Leaf.ly, in fact, other folks on the Windows Azure team have just told me that this is not the case. (The whole point of setting the machineKey element is to ensure that all instances share the same value.)I know, that is why it is so surprising, but it definitely is the case. I can provide you with a staging instance that you can log into and see that the config files are different.
If you could share the info about that deployment, that would be great, actually. Can you email me at Steve.Marx@microsoft.com so we can check it out?
The problem can be easily reproduced by following the steps below:
- Create a new azure project and add a web role to it
- Open the web.config and add machine key to it. Leave the web.config open
- Debug the project and observe
You will be prompted with a dialog box that web.config is modified and do you want to reload it. If you reload it, the machine key line in the web.config is changed.
If the web.config is marked read-only, the debugger throws an exception and the role will not launch. The problem is reported in the post http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/thread/e7cfbefa-afeb-4b7d-997d-55167936eb7d
Yes, that describes the issue. Yes, it's still an issue with SDK 1.3.
As I said, a workaround is coming shortly.
This fixed the issue I was having with my persistent cookies not working after upgrading to 1.3. Every time my app recycled, I would see the following event logged:
Event ID 1315
Forms authentication failed for the request. Reason: The ticket supplied was invalid.
Steve,
A quick question - will this workaround also work for HWC ?
i.e. how it is possible to fix this within HWC as the workaround seems to assume that you are using FullIIS ? The code references
// get the site's web configuration
var siteNameFromServiceModel = "Web"; // update this site name for your site.
which I am assuming it grabs from the <sites> entry ?
If you are using HWC - you don't have this or ?
With HWC, if there's a machineKey in your web.config, it doesn't get touched, so there's no need for this.
thx steve :)
maybe needs to add that to the work around doc ? http://msdn.microsoft.com/en-us/library/gg494983.aspx
Workaround
A workaround is to programmatically update the site-level configuration during role instance start-up.
This does not apply to configurations using Hosted Web Core and only applies to sites using FullIIS with the <sites> element.
|

