成员总是返回false

本文关键字:false 返回 成员 | 更新日期: 2023-09-27 18:16:33

my membership in c# app总是返回false我读过所有类似的问题在堆栈溢出我改变了AppName, passstype .....但我解决不了。谢谢你的帮助。我的c#代码是:

private void BtnEnter_Click(object sender, EventArgs e)
    {            
           bool i = Membership.ValidateUser(txtUserName.Text, txtPass.Text);
            if (i)
            {
                    ClsVariable.UserId=new Guid(Membership.GetUser(txtUserName.Text).ProviderUserKey.ToString());
                    InsertLogin(ClsVariable.UserId.ToString());
                    MainForm fr = new MainForm();
                    fr.Show();
                    Hide();
            }
            else
            {
                MessageBox.Show("username or password is not valid.");
            }
    }

my app.config is:

<configuration>
  <configSections>
  </configSections>
  <connectionStrings>
    <add name="Accountingf.Properties.Settings.DbAccountingConnectionString"
      connectionString="Data Source=SHIMA-PC;Initial Catalog=DbAccounting;Integrated Security=True"
      providerName="System.Data.SqlClient" />
    <add name="Accountingf.Properties.Settings.DbAccountingConnectionString1"
      connectionString="Data Source=SHIMA-PC;Initial Catalog=DbAccounting;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <membership >
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider"
             type="System.Web.Security.SqlMembershipProvider"
             connectionStringName="Accountingf.Properties.Settings.DbAccountingConnectionString"
             requiresQuestionAndAnswer="false"
             enablePasswordRetrieval="true"
             requiresUniqueEmail="false"
             minRequiredPasswordLength="4"
             minRequiredNonalphanumericCharacters="0"
             passwordStrengthRegularExpression="(?=[a-zA-Z0-9])"
             passwordFormat="Clear"
             applicationName="Accountingf"/>
      </providers>
    </membership>
  </system.web>
</configuration>

我改变了我的c#代码,它的工作原理,所以我的通行证和用户名是正确的!

 if(txtUserName.Text=="admin" && txtPass.Text=="1111")
    {
       MainForm fr = new MainForm();
       fr.Show();

成员总是返回false

使用以下命令直接在Database上检查用户的状态

select * from aspnet_Membership
inner join aspnet_Users on aspnet_users.UserId = aspnet_Membership.UserId 
where aspnet_Users.UserName = 'admin'
例如

,您的用户可能被锁定。

您还可以使用所有可用的助手存储过程来确保您拥有正确的密码。我的建议是首先确保用户在数据库级别上工作良好,然后尝试找到代码级别上可能出现的错误。