2010-10-04 71 views
4

我一直在玩弄使用MySql作为asp.net mvc表单身份验证的成员资格提供程序。据我所知,我已经配置了正确的东西,并且我可以通过注册操作和asp.net网络配置站点创建用户。但是,当我尝试与其中一个用户登录时,它不起作用。它会返回错误,就好像我输入了错误的密码,或者该帐户不存在。ASP.NET MVC + MySql会员提供程序,用户无法登录

我已在数据库中验证该帐户是否存在。我在这里按照说明以供参考:http://blog.tchami.com/post/ASPNET-MVC-2-and-MySQL-Membership-Provider.aspx

这里是我的web.config:

<?xml version="1.0"?> 

<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    http://go.microsoft.com/fwlink/?LinkId=152368 
    --> 

<configuration> 
    <connectionStrings> 
     <add name="MySQLConn" connectionString="Server=localhost;Database=intereditor;Uid=<user>;Pwd=<password>;"/> 
    </connectionStrings> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0"> 
     <assemblies> 
     <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     </assemblies> 
    </compilation> 

    <authentication mode="Forms"> 
     <forms 
     loginUrl="~/Account/LogOn" 
     timeout="2880" 
     name=".ASPXFORM$" 
     path="/" 
     requireSSL="false" 
     slidingExpiration="true" 
     enableCrossAppRedirects="false" 
     /> 
    </authentication> 

    <membership defaultProvider="MySqlMembershipProvider"> 
     <providers> 
     <clear/> 
     <add name="MySqlMembershipProvider" 
     type="MySql.Web.Security.MySQLMembershipProvider,MySql.Web,Version=6.3.4.0, Culture=neutral,PublicKeyToken=c5687fc88969c44d" 
     autogenerateschema="true" connectionStringName="MySQLConn" 
     enablePasswordRetrieval="false" enablePasswordReset="true" 
     requiresQuestionAndAnswer="false" requiresUniqueEmail="false" 
     passwordFormat="Hashed" maxInvalidPasswordAttempts="5" 
     minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" 
     passwordAttemptWindow="10" passwordStrengthRegularExpression="" 
     applicationName="/" /> 
     </providers> 
    </membership> 

    <profile defaultProvider="MySqlProfileProvider"> 
     <providers> 
     <clear/> 
     <add name="MySqlProfileProvider" 
     type="MySql.Web.Profile.MySQLProfileProvider,MySql.Web,Version=6.3.4.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d" 
     connectionStringName="MySQLConn" applicationName="/" /> 
     </providers> 
    </profile> 

    <roleManager enabled="true" defaultProvider="MySqlRoleProvider"> 
     <providers> 
     <clear /> 
     <add name="MySqlRoleProvider" 
     type="MySql.Web.Security.MySQLRoleProvider,MySql.Web,Version=6.3.4.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d" 
     connectionStringName="MySQLConn" applicationName="/" /> 
     </providers> 
    </roleManager> 
    <pages> 
     <namespaces> 
     <add namespace="System.Web.Mvc" /> 
     <add namespace="System.Web.Mvc.Ajax" /> 
     <add namespace="System.Web.Mvc.Html" /> 
     <add namespace="System.Web.Routing" /> 
     </namespaces> 
    </pages> 
    </system.web> 

    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false"/> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
</configuration> 

任何人都可以请帮我鉴定什么是错的,这样用户就可以登录?

UPDATE

所以在成员提供者本身的代码调试登录过程后,我发现有在供应商的错误。存储在数据库中的密码哈希和根据输入的密码生成的哈希之间存在差异。作为解决我的问题的一种解决方法,我将密码格式更改为'encrpyted',并将机器密钥添加到我的web.config中。

我仍然有兴趣找出提供程序中散列格式的问题,并且会花费更多的时间对其进行调试,如果我能够弄清楚问题所在,我会整理一个补丁并提交它。

+0

我有同样的问题。感谢您张贴迄今为止已经发现的内容! – 2010-11-12 18:24:35

回答

1

确保用户没有被锁定。 islocked属性在sqlmembershipprovider用来提供注册服务的一个表中(不记得确切的名字:() 即时通讯相当确定这是问题,你需要改变islocked形式为真,以使用该用户的登录凭据登录

+0

我在成员资格表中找到了列,并且该列已被设置为0。 – 2010-10-04 20:06:47