Azure ASP.NET MVC Web.Config Deployment Issue

2019-02-26 06:02发布

问题:

We are developing an ASP.NET MVC web app that will be hosted on Windows Azure. We have deployed the application a few times during development without any problems. It was actually quite surprising how smooth the process went. Then, when we went to deploy the app for beta testing we kept getting 403 Access Denied errors whenever we tried to navigate to the base url of the site. If we tried to navigate to any of the various Controllers and Actions of the site thereafter we would get 404 The resource could not be found errors.

The other strange thing that we noticed is that we had defined the authentication redirect page to be /Access/SignIn rather than the default Account/Login. Everything worked fine on the development machine and we were redirected to /Access/SignIn but when publishing to Azure we saw we were being redirected to /Account/Login. This made us think there was an issue with the web.config file.

We enabled remote desktop on the Azure deployment and took a look at the web.config file only to find out that it was almost completely empty! The only setting in there was the machineKey. We manually copied the web.config from one of our development machines up to the Azure virtual machine instance and everything started to work from there on.

What in the world would make the deployment wipe out the web.config file? And how can we prevent this from happening as we aren't going to be able to update the web.config file manually every time we deploy an update?

回答1:

I often solve these sorts of problems by looking at the contents of the .cspkg file. This allows me to avoid waiting for the Azure package upload and initialization. Here are the steps to view the .cspkg contents:

  1. Navigate to the /bin//app.publish folder
  2. Rename the .cspkg file to .cspkg.zip.
  3. Open .cspkg.zip. You will find a .cssx file (which is really a zip file) for each project referenced by the Azure project.
  4. Extract the .cssx file you wich to inspect and rename it to .cssx.zip
  5. Open the .cssx.zip and look around. For WorkerRoles, check out the approot folder. For WebRoles, check out the sitesroot folder.