【问题标题】:Web App works on localhost but fails on remote connectionWeb App 在本地主机上工作,但在远程连接上失败
【发布时间】:2011-12-15 03:58:28
【问题描述】:

我们正在部署一个新的 ASP.NET Web 应用程序,该应用程序使用一个单独的 DLL,我们也构建了该 DLL,该 DLL 反过来询问 Active Directory 以获得简单的用户和组成员信息。服务器是 Windows Server 2003。

如果我 RDP 到服务器并在 localhost 下浏览它,应用程序工作正常

应用程序当我从单独的 PC 浏览到它时引发以下错误。如果我从服务器上的 RDP 会话浏览到它,它也会引发相同的错误,但在服务器名称下浏览它。

这是一个代码访问安全问题吗?其他想法?

异常详情: System.Runtime.InteropServices.COMException:发生操作错误。

来源错误: 在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。

堆栈跟踪: [COMException (0x80072020):发生操作错误。 ]

   System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +420085
   System.DirectoryServices.DirectoryEntry.Bind() +36
   System.DirectoryServices.DirectoryEntry.get_Name() +32
   USM.UsmAD.get_DomainName() in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\Active Directory Search\USMAD\USMAD\UsmAD.cs:60
   USM.UsmAD.Get_UserGroupNames(String username) in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\Active Directory Search\USMAD\USMAD\UsmAD.cs:190
   AdminWeb.CheckAccessDAL.GetGroupNames() in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\AdminWeb\USMDAL\CheckAccessDAL.cs:28
   AdminWeb.CheckAccessDAL.SetMenuAccess(Menu mnuUSMAdmin) in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\AdminWeb\USMDAL\CheckAccessDAL.cs:89
   AdminWeb.SiteMaster.TrimMainMenus() in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\AdminWeb\AdminWeb\Site.Master.cs:50
   AdminWeb.SiteMaster.Page_Load(Object sender, EventArgs e) in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\AdminWeb\AdminWeb\Site.Master.cs:17
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

【问题讨论】:

  • Web 应用程序以什么安全上下文运行?向 Active Directory 发出请求时 - 传递了哪些凭据?
  • @kd7 没有传递特定的凭据。 Get_UserGroupNames 中的 PrincipalContext 被实例化如下: using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, DomainName + ".com"))`
  • @ChrisLively 诚然,它看起来与此类似,但在域帐户下运行的解决方案不是,至少不是其本身,是解决方案。尽管网站设置为使用集成 Windows 身份验证,但请参阅下面关于现在被挑战登录的评论。
  • 注意:我最初说 Active Directory DLL 在 GAC 中。它不是。它在 BIN 文件夹中。

标签: asp.net active-directory code-access-security


【解决方案1】:

听起来像是 dll 上的烫发问题

尝试允许 IUSR 访问此文件....

【讨论】:

  • 我之前错了。我们实际上还没有将 DLL 部署到 GAC 中。 IURS 可以访问 DLL,IIS_WPG 组也是如此。
  • 告诉我 DLL 是如何工作的,它是使用当前用户凭据访问 AD 还是使用某种硬编码的服务帐户......
  • 没有传入特定的凭据。代码有这样的引用:using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, DomainName + ".com")) { using (UserPrincipal up = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, username)) if (up != null) { using (PrincipalSearchResult<Principal> Groups = up.GetAuthorizationGroups()) { foreach (GroupPrincipal g in Groups)
【解决方案2】:

您可能需要在有权访问与Active Directory 对话所需资源的域级别身份下运行您的应用程序池。

Specify an Identity for an Application Pool (IIS 7)

Configuring Application Pool Identity with IIS 6.0 (IIS 6.0)

如果您需要在运行时执行此操作,这里有一篇文章:

How To: Use Impersonation and Delegation in ASP.NET 2.0

我还鼓励您实现 UnhandledException 处理程序来记录这些运行时错误。

【讨论】:

  • 当我这样做时,该站点现在会提示我登录,并且它从不接受我的域凭据。三次失败后,我收到 401.1 Unauthorized 错误。我是服务器的管理员,所以应该没有问题。该站点继续在 localhost 下运行。
猜你喜欢
  • 2015-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多