【问题标题】:ASP.Net Authentication using <credentials> in web.config在 web.config 中使用 <credentials> 进行 ASP.Net 身份验证
【发布时间】:2011-03-22 22:26:53
【问题描述】:

我需要在网上发布一个演示网站。我需要确保访问该网站的安全。

使用 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

非常感谢,

罗伯

【问题讨论】:

  • 有没有可能是登录成功了,但是下一步(无论打开什么页面)都在尝试执行sql?你能发布其余的 web.config 吗?
  • 您的演示配置中是否还有对成员资格提供程序的引用?
  • 我会发布整个配置文件和整个堆栈跟踪。
  • 如果你想编写自己的使用 XML 文件作为数据源的 MembershipProvider 不会太麻烦。您可以在 XML 文件中添加用户名和密码字段,只需覆盖自定义 MembershipProvider 的 ValidateUser(username, password) 方法。编写自己的 MembershipProvider 不会太难,而且它的好处是您将来也可以重用它。

标签: .net asp.net security authentication


【解决方案1】:

要在 web.config 中使用带有凭据的表单身份验证,您必须使用 FormsAuthentication.Authenitcate 方法。看起来您有默认登录控件正在尝试访问成员资格类。

【讨论】:

  • 你明白了!非常感谢。
【解决方案2】:

首先检查您的身份验证模式。如果 SQLAuthentication,请在连接字符串中提供用户 ID 和密码。

示例:

<"Data source="";Initial Catalog="Dbname";UserId=sa;Password=1234">

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 2010-11-11
      • 1970-01-01
      • 2017-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-12
      • 1970-01-01
      • 2011-06-27
      相关资源
      最近更新 更多