Francis Rodgers
Francis Rodgers

Reputation: 4675

Connection Strings with ASP.Net V3

I am new to MVC 3 and went through lots of cool tutorials. Loving the design pattern and enjoying the productivity boost.

One of the problems I am now having is that I was using the built in database to handle the login that is behind many of the basic MVC apps in most tutorials. I now need to change to access the login details of a live production system this but cant find where to do it.

I initially taught is would be as simple as changing the connection string, but the production database is totally different than the made up example.

It is not obvious to me where the model / controller is getting the data from. For example, where does the model / controller retreive the user name or compair the password. If I knew this then I could alter my solution to point to the correct database / tables / fields.

Also, my real database is modelled in EF and is in a separate project within the same solution. So I have MyProject.Data and MyProject.Web and eventually will have MyProject.Test ect.

Any help here would be greatly appreicated. Thanks in advance.

EDIT 1: The real database also has a login table with user name and password fields, just like the MVC simple login db. However the database is obviously not part of the system like in the sample projects. Instead it is sitting on the server waiting to be accessed.

My problem is that I dont know where to go to make the changes needed. I was thinking it would be the connection string but this is not working. Even the errors I get just point me back to the connection string as opposed to giving me a line of code to find.

Upvotes: 0

Views: 228

Answers (1)

Mirko
Mirko

Reputation: 4282

The framework pulls the connection string that is named the same as the DbContext derived class by default. So look for a connection string that is the same as this class. Having said that this connection string has absolutely nothing to do with the default forms implementation as that pulls from connection string that is identified in the membership section of the web.config. This should look something like this:


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

in there you see the connectionStringName identified. You can of course simply change this, but most likely if you already have an existing database, this will most likely not be structured correctly.

The comment by Henk is most likely right in that you will want to create your own membership provider (simply create a class and inherit from MembershipProvider and implement CreateUser, GetUser, ValidateUser, and ApplicationName (or so I think)). You need to make sure to register this provider in place of the AspNetMembershipProvider. Once you do that you should see breakpoints be hit on your provider and simply implement as you need it for your database/AD/...

Upvotes: 1

Related Questions