0
我想讓UserPro類從User類讀取一個方法,但我一直遇到「The name'Password'在當前上下文中不存在」和「名稱'UserName'不存在於目前情況下」在下面的代碼:驗證用戶詳細信息
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;
}
任何意見,我在哪裏的方法去錯了嗎?非常感謝
謝謝。這有幫助。 – user3070072