C# asp.net mvc 3中的active directory asp.net表单身份验证
我必须实现这样的接口:C# asp.net mvc 3中的active directory asp.net表单身份验证,c#,asp.net,asp.net-mvc,asp.net-mvc-3,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 3,我必须实现这样的接口: interface IMembershipWrapper { Guid GetUserId(); Guid GetUserId(string username, bool userIsOnline); bool ValidateUser(string userName, string password); … } 并使用Unity注入它 对于某些方法,我可能会抛出NotImplementedException异常,但您认为这通常是可能的吗?你推荐什么
interface IMembershipWrapper
{
Guid GetUserId();
Guid GetUserId(string username, bool userIsOnline);
bool ValidateUser(string userName, string password);
…
}
并使用Unity注入它
对于某些方法,我可能会抛出NotImplementedException异常,但您认为这通常是可能的吗?你推荐什么策略
我知道我可以通过web.config配置“active directory asp.net表单身份验证”,如前所述。不幸的是,这不是一个选项。在不更改web.config中的身份验证系统的情况下,这应该是完全可能的。尤其是在使用.NET3.5+时。看一看 要实现
GetUserId(字符串username,bool userIsOnline)
您可能需要尝试以下方法:
public Guid GetUserId(string username, bool userIsOnline) {
using(PrincipalContext pc = new PrincipalContext(ContextType.Domain, "[active directory domain here]")) {
var user = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, username);
if(user != null)
return user.Guid.Value;
else
return null;
}
}
要实现ValidateUser(字符串用户名、字符串密码)
请在PrinicalContext
public bool ValidateUser(string userName, string password) {
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "[active directory domain here]"))
{
return pc.ValidateCredentials(userName, password);
}
}
如果没有关于实现的更多信息,我不知道如何实现
GetUserId()
,因为您似乎没有足够的信息来访问Active Directory。如果不更改web.config中的身份验证系统,这应该是完全可能的。尤其是在使用.NET3.5+时。看一看
要实现GetUserId(字符串username,bool userIsOnline)
您可能需要尝试以下方法:
public Guid GetUserId(string username, bool userIsOnline) {
using(PrincipalContext pc = new PrincipalContext(ContextType.Domain, "[active directory domain here]")) {
var user = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, username);
if(user != null)
return user.Guid.Value;
else
return null;
}
}
要实现ValidateUser(字符串用户名、字符串密码)
请在PrinicalContext
public bool ValidateUser(string userName, string password) {
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "[active directory domain here]"))
{
return pc.ValidateCredentials(userName, password);
}
}
如果没有关于实现的更多信息,我不知道如何实现
GetUserId()
,因为您似乎没有足够的信息来访问Active Directory。Cam您使用Windows身份验证?Cam您使用Windows身份验证?