ASP.NET FormsAuthentication.Authenticate() 不起作用

发布于 2024-08-02 18:37:57 字数 1993 浏览 1 评论 0原文

我已经使用 CreateUserWizard - 控件创建了一个用户。

我的 web.config 文件如下:

<?xml version="1.0"?>

<configuration>

  <appSettings/>

  <connectionStrings>
    <remove name="LocalSqlServer"/>
    <add name="ConnString1" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=IceWebPortal_SQL2K5;user=sa;password=;integrated security=true;" providerName="System.Data.SqlClient"/>
    <add name="LocalSqlServer" connectionString="Data Source=localhost;Initial Catalog=aspnet_membership_test;Integrated Security=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>

  <system.web>
      <!--
          Set compilation debug="true" to insert debugging
          symbols into the compiled page. Because this
          affects performance, set this value to true only
          during development.
      -->
      <compilation debug="true" />
      <!--
          The <authentication> section enables configuration
          of the security authentication mode used by
          ASP.NET to identify an incoming user.
      -->
    <authentication mode="Forms">
      <forms
        name="CookieDemo"
        loginUrl="Default.aspx"
        protection="All"
        timeout="30"
        path="/"
      />
    </authentication>
    <!--<authorization>
      <deny users="?"/>
    </authorization>-->
  </system.web>

  <location path="Default.aspx">
    <system.web>
      <authorization>
        <allow users="*"></allow>
      </authorization>
    </system.web>
  </location>
</configuration>

我发现 FormsAuthentication.Authenticate(用户名,密码); 始终返回 false。

string username = this.usernameTextBox.Text;
string password = this.passwordTextBox.Text;

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

if (success)
{
}

可能是什么问题?

I have created a user by using CreateUserWizard - control.

My web.config file is as follows:

<?xml version="1.0"?>

<configuration>

  <appSettings/>

  <connectionStrings>
    <remove name="LocalSqlServer"/>
    <add name="ConnString1" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=IceWebPortal_SQL2K5;user=sa;password=;integrated security=true;" providerName="System.Data.SqlClient"/>
    <add name="LocalSqlServer" connectionString="Data Source=localhost;Initial Catalog=aspnet_membership_test;Integrated Security=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>

  <system.web>
      <!--
          Set compilation debug="true" to insert debugging
          symbols into the compiled page. Because this
          affects performance, set this value to true only
          during development.
      -->
      <compilation debug="true" />
      <!--
          The <authentication> section enables configuration
          of the security authentication mode used by
          ASP.NET to identify an incoming user.
      -->
    <authentication mode="Forms">
      <forms
        name="CookieDemo"
        loginUrl="Default.aspx"
        protection="All"
        timeout="30"
        path="/"
      />
    </authentication>
    <!--<authorization>
      <deny users="?"/>
    </authorization>-->
  </system.web>

  <location path="Default.aspx">
    <system.web>
      <authorization>
        <allow users="*"></allow>
      </authorization>
    </system.web>
  </location>
</configuration>

I am finding that, FormsAuthentication.Authenticate(username, password); is always returning false.

string username = this.usernameTextBox.Text;
string password = this.passwordTextBox.Text;

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

if (success)
{
}

What can be the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

¢好甜 2024-08-09 18:37:57

您需要添加例如 MembershipProvider 配置 或直接添加用户到 web.config (这可能不是一个好主意)-

示例:

<membership>
    <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider"
             type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
             connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             requiresUniqueEmail="false"
             passwordFormat="Hashed"
             maxInvalidPasswordAttempts="5"
             minRequiredPasswordLength="6"
             minRequiredNonalphanumericCharacters="0"
             passwordAttemptWindow="10"
             passwordStrengthRegularExpression=""
             applicationName="/" />
    </providers>
</membership>

You need to add e.g. a MembershipProvider configuration or add users directly to web.config (which is probably not a good idea)-

Example:

<membership>
    <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider"
             type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
             connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             requiresUniqueEmail="false"
             passwordFormat="Hashed"
             maxInvalidPasswordAttempts="5"
             minRequiredPasswordLength="6"
             minRequiredNonalphanumericCharacters="0"
             passwordAttemptWindow="10"
             passwordStrengthRegularExpression=""
             applicationName="/" />
    </providers>
</membership>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文