【发布时间】:2014-02-06 14:47:11
【问题描述】:
我试图让 UserPro 类从 User 类中读取方法,但我一直遇到“当前上下文中不存在名称‘密码’”和“当前上下文中不存在名称‘用户名’ " 在以下代码中:
public class UserPro : IProvidePrincipal
{
private User _userRepo;
public UserPro (User userRepo)
{
this._userRepo = userRepo;
}
public IPrincipal CreatePrincipal(string username, string password)
{
try
{
if (!_userRepo.Validate(UserName, Password))
{
return null;
}
else
{
var identity = new GenericIdentity(username);
IPrincipal principal = new GenericPrincipal(identity, new[] { "Admin" });
return principal;
}
}
catch
{
return null;
}
}
}
用户类别:
public bool Validate(string UserName, string Password)
{
var user = db.api_login.FirstOrDefault(u => u.username == UserName
&& u.password == Password);
if (user != null)
{
if (user.password == Password)
{
return true;
}
}
return false;
}
我在方法中哪里出错了有什么建议吗?非常感谢
【问题讨论】:
标签: c# asp.net asp.net-mvc-4 asp.net-web-api basic-authentication