C# asp.net应用程序在本地主机上标识用户,但在服务器上标识用户时不使用硬编码用户名/密码

C# asp.net应用程序在本地主机上标识用户,但在服务器上标识用户时不使用硬编码用户名/密码,c#,asp.net-mvc,iis-8,windows-server-2012,C#,Asp.net Mvc,Iis 8,Windows Server 2012,我正在IIS8(windows server 2012)上设置一个新的asp.net站点。我正在尝试使用在WindowsServer2008(IIS6)上运行的旧代码。两者都是虚拟服务器 已启用Windows身份验证 已禁用匿名身份验证。(根据我阅读的一些帖子尝试启用,但没有更改) 通过以下方式获取用户: string user = System.Web.HttpContext.Current.User.Identity.Name; int separatorIndex = user.Last

我正在IIS8(windows server 2012)上设置一个新的asp.net站点。我正在尝试使用在WindowsServer2008(IIS6)上运行的旧代码。两者都是虚拟服务器

已启用Windows身份验证

已禁用匿名身份验证。(根据我阅读的一些帖子尝试启用,但没有更改)

通过以下方式获取用户:

string user = System.Web.HttpContext.Current.User.Identity.Name;

int separatorIndex = user.LastIndexOf(@"\");
if (separatorIndex != -1 && separatorIndex < user.Length - 1)
  {
    user = user.Substring(separatorIndex + 1);
  }

DirectoryEntry rootEntry = new DirectoryEntry("LDAP://na.xxxxxx.biz");

DirectorySearcher directorySearcher = new DirectorySearcher(rootEntry);
directorySearcher.Filter = string.Format("(&(objectClass=user)(objectCategory=user) (sAMAccountName={0}))", user);
directorySearcher.PropertiesToLoad.Add("displayName");

var result = directorySearcher.FindOne();
但是我在旧的代码库中不需要这个,所以我猜IIS8中有一个设置。我玩了一下匿名认证,读了几篇帖子,但还没弄明白


感谢您的帮助。

问题可能是您的应用程序运行的IIS应用程序池的标识不具有查询域的权限,例如LocalService

您应该检查上一个实例上的应用程序池,并确保身份相同或至少具有类似的访问功能

rootEntry.Username = user;
rootEntry.Password = "xxxxxx";