我正在编写一个 ASP.NET MVC 3 网站。这是我的自定义 MembershipProvider(仅 ValidateUser 实现):
public class RFMMembershipProvider : MembershipProvider
{
IUserService userService = new UserService();
public override bool ValidateUser(string username, string password)
{
return password.GetHashCode().ToString() == userService.GetUser(username).Pass;
}
...
}
和我的 Roleprovider(仅实现 GetRolesForUser)
public class RFMRoleProvider : RoleProvider
{
IUserService userService = new UserService();
public override string[] GetRolesForUser(string username)
{
return new string[] { userService.GetRolesForUser(username).Name };
}
...
}
我的 web.config 部分
...
<system.web>
<roleManager enabled="true" defaultProvider="RFMRoleProvider">
<providers>
<clear/>
<add name="RFMRoleProvider" type="RFMSite.WebUI.RFMRoleProvider, RFMSite"/>
</providers>
</roleManager>
<membership defaultProvider="RFMMembershipProvider"
>
<providers>
<clear/>
<add name="RFMMembershipProvider"
type="RFMSite.WebUI.RFMMembershipProvider, RFMSite"
/>
</providers>
</membership>
<authentication mode="Forms" >
<forms loginUrl="~/Account/LogOn" timeout="2880">
</forms>
</authentication>
登录操作:
...
if (Membership.ValidateUser(username, password))
{
FormsAuthentication.SetAuthCookie(username, true);
return RedirectToAction("Files", "Admin");
}
...
return View();
所以问题是为什么当我在 IIS 7.0 上发布站点时Membership.ValidateUser(username, password)
总是返回 false?它在本地 asp.net 开发服务器上正常工作。与 MSSQL Server 的连接是否正常(我可以获取任何数据并在网站部署时显示)?没有异常发生,只是总是返回 false ......