问题
After deploying to Azure, I kept getting server errors -- the application would not run. So I did a remote desktop into the instance and found that the web.config was completely overhauled...what's going on? I thought web.config was packaged as-is? Instead, the entire configuration has been replaced. When I replace the "new" version with the original, unaltered, correct configuration, my app works as intended.
First off, what's going on here? What am I doing wrong? This way I can understand and not replicate this in the future.
Secondly, how do I stop this behavior? I want the original web.config deployed -- not some arbitrary imposter. Thank you!
回答1:
Unless you have a transform specified (using normal, built-in web.config.debug and .release), it doesn't transform any user settings. At one point of time, it did transform the machineKey settings such that your web roles would operate in a web farm scenario (nothing would work behind load balancer if it didn't). I am sure it still does this, but it might be doing it at the machine.config level now (leaving your web.config alone). I haven't checked on this in some time, so not sure what it does now.
Easy way to check what will be deployed is to just package your cskpkg and open up it up as a .zip file. Inside will be another file that has your web role name in it. Open that up as a .zip again and you should see your web site all packaged up. Check the web.config and make sure it is what you need. If not, then post back here what you think shouldn't be changed.
回答2:
Based on dunnry's suggestion to unzip the cskpkg file, I noticed that the web.config was never even packaged -- so Azure must have been creating a basic one out of necessity (without warning me!?!?). After some investigation, I came across this nugget (from another StackOverflow question addressing deployment issues):
Turns out the web.config file wasn't even being included in the deployment package. Somehow the BuildAction of the web.config file got changed from Content to None.
After changing BuildAction back to "Content" my deployment now works as expected.
来源:https://stackoverflow.com/questions/11050151/web-config-altered-drastically-during-azure-deployment