Search code examples
asp.net-mvcazureweb-deploymentdevops-services

"You do not have permission to view this directory or page." Error only after swap into production on Azure


I've a multi-tenant ASP.NET MVC 5 web app running on Azure. I use a staging slot to swap into production after a successful deployment to staging. When I swap both production and staging sites present the message

You do not have permission to view this directory or page.

If I open the web.config in kudu (or ftp) and save with no changes then the message goes and the site loads normally. The same is true if I do this on staging. Something is happening during the swap which stops both web applications from loading properly. Whilst the message is present I can navigate to html files, but any MVC routes show the permission message above.

Notes on my setup

Before I swap I check that both production and staging sites are running properly.

When swapping I set the source as staging and the destination as production. There are no warnings, one setting that has the same value in both slots and two new source settings that will be applied to the destination slot. One a connectionstring and the other an AppSetting.

The default documents are set in the web.config

Other appropriate web.config settings are in place:

<modules runAllManagedModulesForAllRequests="true">

<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

But given that the site loads once I resave the web.config I don't think there is anything wrong with the web.config settings.

This issue started after changing the build to pre-compile views into a single dll. A new config file is generated on the site root PrecompiledApp.config

New build config settings:

/p:PrecompileBeforePublish=true /p:UseMerge=true /p:SingleAssemblyName=AppCode

But again, staging loads after the initial build and deployment. It's only after the swap that the issue arises. And again, if I open the web.config and save without changes the issue is rectified.

Could it be that the App Domain is being shut down but not restarted? What am I missing here?


Solution

  • Application insights module causes this. Only way to fix is to completely remove application insights from your web app.