【问题标题】:Using an existing SqlMembershipProvider database with an ASP.NET MVC app将现有的 SqlMembershipProvider 数据库与 ASP.NET MVC 应用程序一起使用
【发布时间】:2014-01-06 14:17:49
【问题描述】:

我一直在寻找有关如何将现有的会员数据库与新的 mvc 应用程序一起使用的方向。我发现的一切都是关于创建一个新的会员数据库。

我希望将新应用程序简单地指向某个地方的现有数据库,但我无法弄清楚我应该在哪里做。

一如既往地赞赏任何方向。

编辑:我尝试更改连接字符串。成员资格组件似乎继续在 LocalDB 之外运行

这是 we.config。唯一的编辑是在未经编辑的“ASP.NET Web 应用程序”中的连接字符串

    <?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="ApplicationServices" connectionString="Data Source=server;Initial Catalog=aspservicesdb;UID=user;PWD=pass" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <authentication mode="Forms" />

    <membership defaultProvider="AspNetSqlMembershipProvider" userIsOnlineTimeWindow="480">
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="12" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>

    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.webServer>
    <modules>
      <remove name="FormsAuthenticationModule" />
    </modules>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

【问题讨论】:

  • 你能发布你的连接字符串吗? Web.config 的相关部分也可能会有所帮助。
  • 请注意,您使用的连接字符串根本没有指定服务器
  • 什么?我删除了要在此处发布的服务器名称,但连接字符串应该很好。它直接从现有的工作应用程序复制。
  • 我继续发布了整个配置。我再次编辑了连接字符串以确保它正确显示。
  • 哦,我明白了,很抱歉造成混乱。我在此配置中看不到任何成员资格部分。他们在吗?如果没有这样的部分,会员提供者将不知道要使用什么数据库。

标签: c# .net sql-server asp.net-mvc sqlmembershipprovider


【解决方案1】:

在 Global.asax 中,我删除了

AuthConfig.RegisterAuth();

这一行实质上实例化了开箱即用的 Visual Studio 应用程序的默认身份验证行为。

删除它可能不是正确的方法。我得再研究一下,但它已经解决了我的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-17
    • 1970-01-01
    • 1970-01-01
    • 2012-02-24
    • 1970-01-01
    相关资源
    最近更新 更多