使用web.config </credentials>中的<credentials>进行ASP.Net身份验证

时间:2011-03-22 22:26:54

标签: .net asp.net security authentication

我需要将一个演示网站发布到网上。我需要保护对网站的访问权限。

使用SQL Server作为成员资格提供程序的实时网站。但是,对于演示站点,我只能发布到一个简单的Web主机,并且无权访问SQL Server。

我只需要一个用户,他们不需要更改密码等选项。因此,我认为最简单的方法是使用web.config中的成员。我创建如下:

<?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>

我可以使用SHA1哈希来实现这个功能。问题是,它在我输入无效密码时识别出来。但是,当我输入正确的密码时,我得到以下内容:

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'.

我不知道为什么要寻找SQL?有人可以帮忙吗?

我正在使用VS2010和.Net 3.5

非常感谢,

罗布

3 个答案:

答案 0 :(得分:4)

要在web.config中使用凭据进行表单身份验证,您必须使用FormsAuthentication.Authenitcate方法。看起来你有试图访问会员等级的默认登录控件。

答案 1 :(得分:0)

我将根据错误中用户名的格式猜测,您的web.config中仍然有Integrated Security=True的连接字符串,并且页面上有一些控件正在打开这是从SQL请求数据。

答案 2 :(得分:0)

首先检查您的身份验证模式。如果您的连接字符串中有SQLAuthentication,Give UserId和Password。

Exameple:

<"Data source="";Initial Catalog="Dbname";UserId=sa;Password=1234">
相关问题