angularsen
angularsen

Reputation: 8668

Error 403 forbidden when running MVC4 on Azure

When creating a brand new MVC4 web role project in VS2012 it gives a HTTP error 403 when publishing and running on Azure. Running locally is fine both when running the MVC4 assembly and when running the Azure deployment assembly with the MVC4 assembly as a web role.

Upvotes: 0

Views: 1933

Answers (2)

angularsen
angularsen

Reputation: 8668

I spent a lot of time figuring this out. No relevant hits on Google, so I ended up creating a new MVC4 project, but this time creating it by going via the deployment assembly's wizard for adding MVC4 web roles (right-click). This worked.

The few differences in web.config gave me hints that the first MVC4 assembly was created on .net 4.5 and had been changed to .net 4.0 by me, while the second one was created directly for .net 4.0. That is how I finally found the MVC4 release notes:

One of the bullet points clearly states my exact situation:

403 Forbidden when running an ASP.NET MVC 4 application on Azure after changing to target 4.0 from 4.5:

If you change an ASP.NET MVC 4 project to target 4.0 after targetting 4.5 and then deploy to Azure you may see a 403 Forbidden error at runtime. To workaround this issue add the following to your web.config: <modules runAllManagedModulesForAllRequests="true" />

Next time I will look through the release notes more carefully for new releases.

Upvotes: 1

Itye
Itye

Reputation: 165

Try adding this to web.config, after System.WebServer:

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

Upvotes: 0

Related Questions