Problems getting Forms Authentication to work with a child MVC asp.net application

Recently we had an issue where we were trying to create an MVC (I think MVC5) web app that was going to be a virtual application off of a parent .net webforms application. By this I mean that the root of the site was a webforms app, and the new MVC app being created was ~/Whatever.

We were having some problems getting the authentication ticket from the parent site to work in the new MVC app. Both sites were running under the same app pool. We had other apps running the same way without problem. What was the issue?

Well, I believe it turned out to be that the MVC app specified .net 4.5 in it’s web.config file, while the root application was running with .net 4.0. The problem line was:

<httpRuntime targetFramework=”4.5″ />

As soon as we removed that line from the web.config it started working.

This stackoverflow post seems to suggest the same thing (not the answer with 3 upvotes, the one with 26).

http://stackoverflow.com/questions/12021863/upgrading-to-asp-net-4-5-mvc-4-forms-authentication-fails

It says:

If your forms authentication ticket needs to be shared between applications using an older version of the .NET framework, you must explicitly configure your .NET 4.5 apps to use the earlier machine compatibility modes, or they will not be able to encrypt/decrypt the forms authentication ticket.

In your .net 4.5 application’s web.config, set the compatibility mode attribute:

<system.web>
<machineKey compatibilityMode=”Framework20SP2″ />
</system.web>

This will allow your .NET 4.5 apps to work with forms authentication tickets generated by earlier .NET versions.

Note: If any of your servers do not have .NET Framework 2.0 SP2 installed, you will need to set the compatibility mode to “Framework20SP1” instead.

We didn’t do this exact same fix, we just removed the one line from the new webapp’s web.config, but it sounds like the same problem.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s