I migrated from MVC 2 to MVC 4. I use the Facebook Javascript API for authentication, so the user logs in via Facebook and I just get their Facebook Id. If their Facebook login attempt was successful, in MVC 2, I simply did this to log them into my site, so that they can access methods which have the [Authorize] attribute:
FormsService.SignIn(user.UserName, true);
Now after moving to MVC 4, my Facebook login process still works fine, but even after doing a FormsService.SignIn, the user does not seem to be authenticated. HttpContext.User.identity.IsAuthenticated is false. And as a result, they cannot access methods with the [Authorize] attribute.
My MVC 4 web.config looks like this:
<profile defaultProvider="DefaultProfileProvider">
<providers>
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</profile>
<membership defaultProvider="UserMembershipProvider">
<providers>
<!--<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />-->
<add name="**UserMembershipProvider**" type="MyProject.Models.UserMembershipProvider" applicationName="/" />
</providers>
</membership>
<roleManager defaultProvider="DefaultRoleProvider">
<providers>
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
</providers>
</sessionState>
As you can see I was using a custom membership provider called “UserMembershipProvider” in MVC 2 (though it wasn’t really used after I moved to Facebook authentication), and I copied over the same thing to MVC 4.
What am I missing?
Thanks.
Any chance that when you upgraded the forms auth section in web.config was removed/updated?