我一直在搞这一整晚,这是非常令人沮丧的。我最终得到了网页显示,但由于某种原因,它不起作用,这意味着它将我拍回我的错误页面,并声明“无法验证用户请再试一次!”。我无法弄清楚这一点,因为这可以在我的本地机器上完美地发现安装了视觉工作室。Asp.net网页与Windows身份验证aganst活动目录
如果有人可以抽出时间帮助解决这个问题,我一整天都在为之奋斗。感谢
Class.cs
public bool IsUserInSetup(string groupName, UserPrincipal user)
{
PrincipalContext context = new PrincipalContext(ContextType.Domain, "DomainName");
GroupPrincipal group = GroupPrincipal.FindByIdentity(context, "GroupName");
if (user.IsMemberOf(group))
{
return true;
}
return false;
}
Authentication.aspx.cs
if (!IsPostBack)
{
if (Request.IsAuthenticated)
{
if (gv.IsUserInSetup("GroupName", user))
{
Session["userValue"] = UserPrincipal.Current;
Response.Redirect("Default.aspx");
}
else
{
lblInfo.Text = "Could Not Authenticate User Please Try Again!";
lblInfo.Text += "<br><b>Name: </b>" + User.Identity.Name;
lblInfo.Text += "<br><b>Authenticated With: </b>";
lblInfo.Text += User.Identity.AuthenticationType;
}
感谢您的回应,我创建了一个应用程序池并使用了Domain \ Admin凭据,但仍然是同一个故事。我注意到,如果我没有启用模拟,我得到以下错误?无法转换类型为“System.DirectoryServices.AccountManagement.GroupPrincipal”的对象以键入“System.DirectoryServices.AccountManagement.UserPrincipal”。 – Henry 2013-04-07 12:18:59