2

I have been looking for direction on how to use an existing membership db with a new mvc app. Everything I've found is in regard to creating a new membership db.

I would expect to simply point the new app to the existing db somewhere, but I haven't been able to figure out where I should do that.

Any direction is appreciated as always.

edit: I have tried changing the connection string. The membership component appears to continue to run off LocalDB

Here's the we.config. The only edit is to the connection string in an otherwise unedited "ASP.NET Web Application"

    <?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>
tintyethan
  • 1,772
  • 3
  • 20
  • 44
  • Can you post your connection string? Relevant part of Web.config might be helpful as well. – Andrei Jan 06 '14 at 14:25
  • Note that the connection string you are using does not specify server at all – Andrei Jan 06 '14 at 14:44
  • What? I removed the server name to post here, but the connection string should be good. Its copied directly from an existing, working application. – tintyethan Jan 06 '14 at 14:52
  • I went ahead and posted the whole config. I edited the connection string again to be sure it appears correctly. – tintyethan Jan 06 '14 at 14:59
  • Oh, I see, sorry for confusion. I do not see any membership sections in this config. Are they there? If there is no such section, membership provider won't know what DB to use. – Andrei Jan 06 '14 at 15:04
  • Ok - right. So what's strange is that membership is working out of the box. I can create a profile and log in, but its using localdb. So I'm not clear on whether the membership bits should be added manually in the web config, or if that's handled somewhere else. – tintyethan Jan 06 '14 at 15:10
  • You can add them manually. In fact you should - at least this is what [MSDN says](http://msdn.microsoft.com/en-us/library/6e9y4s5t%28v=vs.100%29.aspx). – Andrei Jan 06 '14 at 15:18
  • I've added the membership bits but the result is the same. The application is continuing to use LocalDB. I've updated my original above. – tintyethan Jan 06 '14 at 15:43
  • You have specified a different default provider. It should be ` – Andrei Jan 06 '14 at 15:50
  • Thanks for working through this. I still get the same result. I've updated the above to reflect the change. – tintyethan Jan 06 '14 at 15:59
  • Well, I have just one more thing to think about. Make sure that whenever you are using the membership provider in code - this is indeed `AspNetSqlMembershipProvider`. You can debug and view the property `Membership.ProviderName` to ensure that. – Andrei Jan 06 '14 at 16:11
  • I had to remove AuthConfig.RegisterAuth(); from global.asax – tintyethan Jan 06 '14 at 16:27

1 Answers1

0

In Global.asax, I removed

AuthConfig.RegisterAuth();

This line essentially instantiates default authentication behavior for out-of-the-box Visual Studio apps.

Removing this may not be the correct way to go. I'll have to look into it a bit more, but it has solved my problem.

tintyethan
  • 1,772
  • 3
  • 20
  • 44