I have two applications in the same domain, like this:
http://example.com/MvcApp
http://example.com/WebFormsApp
As expected, one is ASP.NET MVC 5, the other is Web Forms, both using .NET framework 4.6.1.
The MVC App
In the ASP.NET MVC 5, I'm creating the forms authentication cookie like this:
var ticket = new FormsAuthenticationTicket(1,
userName,
DateTime.Now,
DateTime.Now.AddMinutes(30),
true,
userData,
FormsAuthentication.FormsCookiePath
);
var encTicket = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
Response.Cookies.Add(cookie);
My web.config looks like this:
<system.web>
<authentication mode="Forms">
<forms name=".ASPXFORMSAUTH" loginUrl="/Account/Login" defaultUrl="default.aspx" protection="All" timeout="60" path="/" requireSSL="false" slidingExpiration="true" enableCrossAppRedirects="false" cookieless="UseDeviceProfile"/>
</authentication>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" />
<machineKey validationKey="D011D22E385D3BC154D5CF0FCC15EF4843A468FB866FD6EEC533E1E30E6F097232DD9698E62DE6F176BA0DAB9E6925089EB25B20C57C659DD52F78DC025E192B" decryptionKey="5A350E0E7EDF07E5633B492B2F1A17ABC4DF5CF55C8922BD021C344ACE66CA42" validation="SHA1" decryption="AES"/>
</system.web>
Web Forms App
In the web forms app, the web.config looks as follow:
<system.web>
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="pt-BR"/>
<customErrors mode="Off"/>
<authentication mode="Forms">
<forms name=".ASPXFORMSAUTH" loginUrl="che-login-win.aspx" defaultUrl="default.aspx" protection="All" timeout="60" path="/" requireSSL="false" slidingExpiration="true" enableCrossAppRedirects="false" cookieless="UseDeviceProfile"/>
</authentication>
<identity impersonate="true"/>
<authorization>
<deny users="?"/>
</authorization>
<machineKey validationKey="D011D22E385D3BC154D5CF0FCC15EF4843A468FB866FD6EEC533E1E30E6F097232DD9698E62DE6F176BA0DAB9E6925089EB25B20C57C659DD52F78DC025E192B" decryptionKey="5A350E0E7EDF07E5633B492B2F1A17ABC4DF5CF55C8922BD021C344ACE66CA42" validation="SHA1" decryption="AES"/>
<httpRuntime requestValidationMode="2.0" maxRequestLength="8192" executionTimeout="9999"/>
</system.web>
As you may have noticed, both web.configs are using the same name for the forms
tag, and they are using the same machine key attributes. They reside inside the same website in my IIS, under the same domain (there are no subdomains).
When I login in the MVC app, if I open the browser console, I can see the Cookie there with the name I set in web.config.
However, if I open the web forms app, it redirects me to the login page, as if I wasn't logged in. When I open the browser console in the web forms app tab, I can see the cookie there as well.
The web forms project has a login page which creates the Forms Ticket and the Cookie likewise the MVC does, and when I login from there, it works.
What am I missing?