ASP.NET,未知的身份验证机制
在win7 64位系统下开发的网站,要集成AD域认证,在开发环境一切正常,部署到server2003上,iis设置集成windows认证,运行时总是报错“未知的身份验证机制”。
主要涉及到两个文件,LoginPage.cs负责获取域用户名,首先判断在数据库中是否存在匹配的记录,如果有则获取用户信息后正常访问,如果没有则调用AdHelper.cs中的GetUserValue方法去AD域中查询,把查询的结果写入数据库,然后正常访问。
LoginPage.cs
public string ULogin()
{
string errorMsg;
string username;
username = Page.User.Identity.Name;
if (Session["IsLogin"] == null)
{
UserSystem userSystem = new UserSystem();
User userInfor = new User();
userInfor = userSystem.Get_SintUser(username);
if (userInfor == null)
{
AdHelper adHelper = new AdHelper();
User userAD = new User();
userAD = adHelper.GetUserValue(username);
if (userAD != null)
{
userAD.FUserName = username;
userAD.FStatus = 1;
userAD.FIsAdmin = 0;
userAD.FCreateTime = DateTime.Now;
}
}
}
}
AdHelper.cs
public string adPath = ConfigurationManager.AppSettings["LDAP"].ToString();
public string adUserName = ConfigurationManager.AppSettings["adUserName"].ToString();
public string adUserPassword = ConfigurationManager.AppSettings["adUserPassword"].ToString();
/// <summary>
/// 根据用户名获取用户信息
/// </summary>
/// <param name="username">用户名</param>
/// <returns>User</returns>
public User GetUserValue(string username)
{
DirectoryEntry entry = new DirectoryEntry(adPath, adUserName, adUserPassword);
User user = new User();
try
{
object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("Employeeid");
search.PropertiesToLoad.Add("displayname");
SearchResult result = search.FindOne();
if (null == result)
{
return null;
}
user.FUserNumber = result.Properties["Employeeid"][0].ToString();
user.FUserFullName = result.Properties["displayname"][0].ToString();
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}
entry.Close();
return user;
}
请各位大侠帮忙解决!! asp.net AD域
------解决方案--------------------
config中配置验证方式节换成window试试?