ASP.NET Membership.ValidateUser()总是返回"假" [英] ASP.NET Membership.ValidateUser() always return "false"

查看:151
本文介绍了ASP.NET Membership.ValidateUser()总是返回"假"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的web.config:

Here is my web.config:

<membership defaultProvider="CustomizedMembershipProvider">
  <providers>
    <clear />
    <add name="CustomizedMembershipProvider" 
         connectionStringName="MYbdName" 
         applicationName="/" type="System.Web.Security.SqlMembershipProvider" 
         requiresQuestionAndAnswer="false" 
         passwordFormat="Clear" 
         enablePasswordRetrieval="true" 
         requiresUniqueEmail="true" 
         minRequiredPasswordLength="4" 
         minRequiredNonalphanumericCharacters="0" />
  </providers>
</membership>

我甚至很难codeD上的用户名和密码:

I even hardcoded the username and password:

 bool b = Membership.ValidateUser("user@mail.com", "pass123");

当我在数据库中执行select,我得到了正确的用户。

When i perform a select on database i get the correct user.

用户isAproved = TRUE

User isAproved = true

用户isLockedout = 0

User isLockedout = 0

推荐答案

您需要设置的applicationName 属性配置ASP.NET 2.0成员和其他供应商的时候。在你的web.config,它缺少:

You need to set the applicationName property when configuring ASP.NET 2.0 Membership and other Providers. In your web.config, it's missing:

<membership defaultProvider="CustomizedMembershipProvider">
  <providers>
    <clear />
    <add name="CustomizedMembershipProvider" 
         connectionStringName="MYbdName" 
         applicationName="/"   <----------   Missing applicationName
         type="System.Web.Security.SqlMembershipProvider" 
         requiresQuestionAndAnswer="false" 
         passwordFormat="Clear" 
         enablePasswordRetrieval="true" 
         requiresUniqueEmail="true" 
         minRequiredPasswordLength="4" 
         minRequiredNonalphanumericCharacters="0" /> 
  </providers>
</membership>

您可以尝试在这里得到的值

You can try to get the value here

public bool Login(string userName, string password)
{
    var provider = Membership.Provider;
    string name = provider.ApplicationName; // Get the application name here

    return Membership.ValidateUser(userName, password);
}

或打开 aspnet_Users aspnet_Applications ASPNETDB内表数据库,并弄清楚创建发展过程中的用户和其他数据时发生了什么使用的应用程序名称(看看 aspnet_Application 表工作了这一点)。

or open up the aspnet_Users and aspnet_Applications tables within the ASPNETDB database and figure out what application name was used when creating the users and other data during development (look in the aspnet_Application table to work this out).

然后正确地设置属性在web.cofig:

Then correctly set the property in your web.cofig:

<membership defaultProvider="CustomizedMembershipProvider">
      <providers>
        <clear />
        <add name="CustomizedMembershipProvider" 
             connectionStringName="MYbdName" 
             applicationName="MyAppName"   <----------   correct
             type="System.Web.Security.SqlMembershipProvider" 
             requiresQuestionAndAnswer="false" 
             passwordFormat="Clear" 
             enablePasswordRetrieval="true" 
             requiresUniqueEmail="true" 
             minRequiredPasswordLength="4" 
             minRequiredNonalphanumericCharacters="0" /> 
      </providers>
    </membership>

有关详细信息,请阅读本<一个href=\"http://weblogs.asp.net/scottgu/archive/2006/04/22/Always-set-the-_2200_applicationName_2200_-property-when-configuring-ASP.NET-2.0-Membership-and-other-Providers.aspx\"相对=nofollow>从斯科特谷的博客文章。

For more details, read this article from Scott-Gu's blog.

这篇关于ASP.NET Membership.ValidateUser()总是返回&QUOT;假&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆