Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net Authentication using <credentials> in web.config

I need to publish a demo website to the web. I need to secure access to the site.

The live site with use SQL Server as the membership provider. However, for the demo site I can only publish to a simple web host and have no access to SQL Server.

I need only a single user, and they don't need option to change password etc. Therefore, I thought easiest way to achieve this would be to use the member of within the web.config. I have created as follows:

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <system.web>
      <authentication mode="Forms">
      <forms name="ProjectApple" loginUrl="~Login.aspx">
        <credentials passwordFormat="Clear">
          <user name="lawyer" password="Super12."/>
        </credentials>
      </forms>
    </authentication>
    <compilation debug="true"/>
  </system.web>
</configuration>

I will use SHA1 hash when I can get this working. Problem is, it recognises when I've entered an invalid password. However, when I enter the correct password I get the following:

Cannot open user default database. Login failed.
Login failed for user 'RB-T510\Rob'. 
Description: An unhandled exception occurred during the execution of the current web          request. Please review the stack trace for more information about the error and where it   originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Cannot open user default   database. Login failed.
Login failed for user 'RB-T510\Rob'.

I don't know why it's looking for SQL? Can anyone help please?

I'm using VS2010 and .Net 3.5

Many thanks,

Rob

like image 427
Rob Bowman Avatar asked Mar 22 '11 22:03

Rob Bowman


1 Answers

To use forms authentication with credentials in web.config you must use FormsAuthentication.Authenitcate method. Looks like you have default Login control that is trying to access membership class.

like image 176
gbs Avatar answered Sep 28 '22 07:09

gbs