ASP.Net MVC 5 using webconfig credentials and Membership.ValidateUser method

965 views Asked by At

I am storing a single credential in my Web.config file the usual way:

    <authentication mode="Forms">
      <forms loginUrl="~/Login" timeout="2880">
        <credentials passwordFormat="Clear">
          <user name="admin" password="123" />
        </credentials>
      </forms>
    </authentication>

I am fully aware of the TOP NOTCH security and password strength :).

Then in my Custom AuthProvider class I validate the user the usual (old) way:

bool result = FormsAuthentication.Authenticate(username, password);

And it works fine, however, that method is deprecated (obsolete). So I want to use the new way (which I believe to be the right thing):

bool result = Membership.ValidateUser(username, password);

But I get exception:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

There obviously isn't truly a problem accessing the database, since I am showing "unauthenticated" content from it perfectly fine.

So my question is... what is the new solution to save credentials in the Web.config without using deprecated methods? I figured others might run into the same issue and I am very curious to understand why this is happening...

Thank you in advance!

1

There are 1 answers

0
DarkVision On

there is no equivalent in the api for FormsAuthentication.Authenticate in MVC 5 if you use Membership.ValidateUser you need to define membership in webconfig usually the server that give role to the user like a active directory server.