从Active Directory获取asp.net web表单C#
问题描述:
用户信息,我通过IIS从Active Directory获取asp.net web表单C#
托管Web表单您可以通过使用Active Directory用户名和密码
我如何获得其它信息登录到这份表单网站该用户喜欢的名字和姓氏从Active Directory 的,这是我目前在页面加载代码成功登录后,
protected void Page_Load(object sender, EventArgs e)
{
FormsIdentity id = (FormsIdentity)User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
Response.Write("<p/>TicketName: " + ticket.Name); //this ticket.name is the current username logged to the form
Response.Write("<br/>Cookie Path: " + ticket.CookiePath);
Response.Write("<br/>Ticket Expiration: " +
ticket.Expiration.ToString());
Response.Write("<br/>Expired: " + ticket.Expired.ToString());
Response.Write("<br/>Persistent: " + ticket.IsPersistent.ToString());
Response.Write("<br/>IssueDate: " + ticket.IssueDate.ToString());
Response.Write("<br/>UserData: " + ticket.UserData);
Response.Write("<br/>Version: " + ticket.Version.ToString());
}
其他信息,我在网上使用的身份验证模式=“窗口”。配置 框架4.0
答
尝试使用PrincipalContext
。 例如手动检查用户密码,您可以使用此代码:
using (var context = new PrincipalContext(ContextType.Domain, "MyAdName"))
{
var isValidUser = context.ValidateCredentials(model.UserName, model.Password);
if (!isValidUser)
{
//Do the staff
}
}
你可以找到你context
想要什么。
而且还请这个帖子:这里get first name last name of logedin windows user?
一些东西真腥。 他们标记了我自己的答案。 这个答案可以帮助很多人在未来。 这个论坛有些问题。他们继续报告每一个问题,现在我的答案。 – listojay