Upgrading to ASP.NET 4.5/MVC 4 forms authentication fails

后端 未结 3 1829
清歌不尽
清歌不尽 2020-12-03 01:41

I\'ve just downoaded a VS 2012 along with ASP.NET 4.5 and MVC 4.0 and was kicking the tires with a sample app and found that the forms authentication that works perfectly wi

相关标签:
3条回答
  • 2020-12-03 02:15

    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.

    MSDN - MachineKeySection.CompatibilityMode Property

    0 讨论(0)
  • 2020-12-03 02:35

    For me, I had an issue because there are some changes to the web.config settings you need (from http://www.asp.net/whitepapers/mvc4-release-notes)

    <appSettings>
      <add key="webpages:Version" value="2.0.0.0" />
      <add key="PreserveLoginUrl" value="true" />
    </appSettings>
    

    Fixing these settings (which it doesn't look like you've added) got things working for me when I had login issues.

    0 讨论(0)
  • 2020-12-03 02:38

    The issue here is that the default mvc4 internet template is using SimpleMembership to manage membership/roles information. The code in the template has assumption of this and can only work with simplemembership. When you install universal providers the account controller code blows up since it cannot understand universal providers. Look at this post which explains further on this scenario http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx

    0 讨论(0)
提交回复
热议问题