使用 ASP Identity 中的表单身份验证表

Using the forms authentication tables in ASP Identity

我有一个在 asp.net 中使用 Forms 身份验证创建的数据库,但现在我想开发另一个使用相同用户名和密码的应用程序,并且应该能够登录到新的应用程序使用 MVC 5 Aspnet Identity 开发。所以我希望能够使用他们的旧信用在新应用程序中对用户进行身份验证。

我的旧数据库结构

我知道 Asp Identity Individual Authentication mode 将生成其他表集我也想停止此默认行为,因为我不希望在旧数据库中创建 Iddentity 表。

请指导我如何实现这一目标。谢谢

Web 窗体和 MVC 默认都使用 ASP.NET 成员资格。如果您的旧应用程序使用成员资格提供程序,那么将它改编为 MVC 应该相当容易。如果没有,您可以选择创建使用现有数据库的新成员身份提供程序或替换 MVC 应用程序的身份验证机制。

我建议将此作为您研究的起点:http://weblogs.asp.net/jongalloway/asp-net-mvc-authentication-customizing-authentication-and-authorization-the-right-way

或者,您可以通过多种方式将用户帐户从旧应用程序迁移到新 MVC 应用程序。如果不需要向后兼容旧应用程序,这可能是您最好(最简单)的选择。

所以在我尝试过的事情之后。我已经开始工作了。

1) 为 Web 提供商安装 nuget 包

Install-Package Microsoft.AspNet.Providers.Core

2) 复制这些网络配置部分并将它们添加到部分

下的网络配置中
<profile defaultProvider="DefaultProfileProvider">
      <providers>
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </profile>
    <membership defaultProvider="DefaultMembershipProvider">
      <providers>
        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=2.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="/" />
      </providers>
    </membership>
    <roleManager defaultProvider="DefaultRoleProvider">
      <providers>
        <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </roleManager>

3) 将您的默认连接字符串指向包含用户的现有数据库,或者您可以添加新的连接字符串并在上面的 Web 配置部分中使用该名称,将 "DefaultConnection" 替换为 "newConnection"

现在你可以开始了。

只需通过Membership.ValidateUser("username","password")

验证用户的合法性