简体   繁体   English

DefaultAppPool是否在IIS上带有特殊提升的特权运行?

[英]Does DefaultAppPool run with special elevated privilegs on IIS?

I'm running a piece of code within a web page that queries the IIS metabase using ADSI. 我正在网页上运行一段代码,该页面使用ADSI查询IIS元数据库。 The code is as simple as this: 代码很简单:

        DirectoryEntry iisNode = 
        new DirectoryEntry("/LM/W3SVC/1/ROOT/MyAspWebsite-1-128886021498831845");
        foreach (DirectoryEntry de in iisNode.Parent.Children)
        {
            System.Console.WriteLine(de.Name);
        }

This works fine when I run the page/site under the DefaultAppPool on IIS7/W2K8. 当我在IIS7 / W2K8上的DefaultAppPool下运行页面/站点时,此方法运行良好。 However when I create my own app pool and leave the properties the same as the default app pool, this code fails with the following error: 但是,当我创建自己的应用程序池并使属性与默认应用程序池相同时,此代码将失败,并显示以下错误:

Caught: System.Runtime.InteropServices.COMException
Failed to parse virtual directory: 
      /LM/W3SVC/1/ROOT/MyAspWebsite-1-128889542757187500
System.Runtime.InteropServices.COMException (0x80070005): Access is denied.

What special privileges does the DefaultAppPool have? DefaultAppPool有哪些特殊特权? I don't see any documented. 我没有任何记录。 I need this to work in non default app pools, but without giving the entire worker process elevated privileges. 我需要它在非默认应用程序池中工作,但又不赋予整个工作进程更高的特权。 I've also tried using the username and password parameters of the DirectoryEntry constructor, by using the Admin on the machine that IIS7 is running on, but that didn't change anything. 我还尝试了使用DirectoryEntry构造函数的用户名和密码参数,方法是在运行IIS7的计算机上使用Admin,但这没有任何改变。 I'll also note that this works fine on IIS6 and W2K3. 我还将注意到,这在IIS6和W2K3上可以正常工作。

Any help is appreciated. 任何帮助表示赞赏。

You might not realize it, but the actual identity running your code may not be the same as the one listed for w3wp.exe in process explorer. 您可能没有意识到,但是运行代码的实际身份可能与进程资源管理器中为w3wp.exe列出的身份不同。 You should set a breakpoint or run WindowsIdentity.GetCurrent().Name near the offending line of code (DirectoryEntry.Parent.Children) that throws the COMException / "Access denied" violation. 您应该设置一个断点或在引发COMException /“拒绝访问”冲突的有问题的代码行(DirectoryEntry.Parent.Children)附近运行WindowsIdentity.GetCurrent().Name

For example, for me, my App Pool process, w3wp.exe, was running as NETWORK SERVICE in the task manager window, as you described above as well. 例如,对于我来说,我的应用程序池进程w3wp.exe在任务管理器窗口中也作为NETWORK SERVICE运行,如上所述。 However, when I checked the actual runtime identity, it turned out it was the new IIS7 built-in user IUSR , which was different from the value I'd get in IIS6, which was NETWORK SERVICE . 但是,当我检查实际的运行时身份时,原来是新的IIS7内置用户IUSR ,它与我在IIS6中获得的值NETWORK SERVICE

using System.Security.Principal;

Console.WriteLine(
    WindowsIdentity.GetCurrent().Name); // IUSR on IIS7, NETWORKSERVICE on IIS6
foreach (var de in DirectoryEntry("/LM/W3SVC/1/ROOT/MySite".Parent.Children))
{
    System.Console.WriteLine(de.Name);
}

It seems that in IIS6, NETWORK SERVICE had permission to explore the IIS Metabase through the Active Directory Service Interface ( ADSI ) with the DirectoryEntry class. 似乎在IIS6中,NETWORK SERVICE有权通过具有DirectoryEntry类的Active Directory服务接口( ADSI )浏览IIS配置数据库 The new IUSR identity in IIS7, however, does not. 但是,IIS7中没有新的IUSR身份。 In order to run the above code, you'll have to directly impersonate an account with existing ADSI read privileges, for example: 为了运行上面的代码,您必须直接模拟具有现有ADSI读取权限的帐户 ,例如:

using (new MyImpersonationWrapper("admin","pass"))
{
    foreach (var de in DirectoryEntry("/LM/W3SVC/1/ROOT/MySite".Parent.Children))
    {
        System.Console.WriteLine(de.Name);
    }
}

Implementing your own impersonation wrapper and securing a proper local account is an exercise I'll leave to you, as your (security) needs may vary. 由于您(安全)的需求可能会有所不同,因此我将留给您实施自己的模拟包装器并保护适当的本地帐户的安全。

Alternatively, you should be able to look up your desired information using the WMI provider for IIS7 instead, as suggested on this MSDN blog post . 或者,您应该能够使用MIIS 博客文章中建议的使用IIS7WMI提供程序来查找所需的信息。

It is a little hard to tell from your description exactly what might be going on but from what I understand you have a setup like this: 从您的描述中很难确切地知道可能会发生什么,但是据我了解,您有这样的设置:

DefaultWebSite
  |
  +-- VirtualDirectory
        |
        +-- ShowIISMetaData.aspx

I think the problem is that the page that is supposed to show the IIS MetaData is attempting to look at the children of its parent (in other words its siblings). 我认为问题在于应该显示IIS MetaData的页面正在尝试查看其父级(即兄弟姐妹)的子级。

foreach (DirectoryEntry de in iisNode.Parent.Children)

This will only work if the application pool for the default website and the virtual directory are the same physical pool. 仅当默认网站的应用程序池和虚拟目录是相同的物理池时,这才起作用。

There is some information missing from this issue. 此问题缺少一些信息。 Both accounts are running under the same user account so the behaviour should be the same. 两个帐户都在同一个用户帐户下运行,因此行为应相同。 I suggest you try running the code under a vanilla install of IIS, does the problem still occur? 我建议您尝试在原始安装的IIS下运行代码,问题仍然存在吗?

As others have alluded to, if the accounts are the same, its because you have made some modification of the metabase. 正如其他人提到的那样,如果帐户相同,那是因为您对元数据库进行了一些修改。

The credentials associated with the app pool will be the one used when attempting to query AD. 与应用程序池关联的凭据将是尝试查询AD时使用的凭据。 So if both App pools are running under the same credentials that is not your problem. 因此,如果两个应用程序池都在相同的凭据下运行,那不是您的问题。

Do you have different authentication setting in place in your test sites? 您的测试站点中是否有其他身份验证设置? If for example, you have integrated selected on one and not another ... that may explain the behavior you're experiencing. 例如,如果您已将所选内容集成在一个而不是另一个上……这可能可以解释您遇到的行为。

I would check to make sure that the NetWorkServices user has access to the physical directories that it is trying to access. 我将检查以确保NetWorkServices用户有权访问它尝试访问的物理目录。 It appears by the error that you are accessing different sites under the one that works and one that does not, is that correct? 错误显示您正在访问一个有效站点,而另一个无效站点下的访问其他站点,对吗?

As stated by the previous user there is nothing special about the Default AppPool and one you create (unless you change the settings of the custom AppPool. IIS does use the permissions of whatever user is setup to run the AppPool under. 如前一个用户所述,默认的AppPool和您创建的内容没有什么特别的(除非您更改自定义AppPool的设置。IIS会使用任何设置用户的权限在其下运行AppPool。

I would check the path that you are accessing the directory entry on. 我将检查您正在访问目录条目的路径。 Its possible that you may have some conflicting service. 您可能有一些冲突的服务。 Check your event viewer. 检查事件查看器。

This link goes to someone who had a similar problem and found that because Skype was running on port 80 it was causing a conflict with the path. 该链接指向存在类似问题的人,他们发现由于Skype在端口80上运行,导致与路径发生冲突。

But the real answer to your question is "No, there isn't anything special about the default app pool". 但是,对您问题的真正答案是“不,默认应用程序池没有什么特别之处”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IIS 7:标识'IIS APPPOOL \\ DefaultAppPool'没有足够的权限来访问临时目录 - IIS 7: Identity 'IIS APPPOOL\DefaultAppPool' does not have sufficient permission to access the temp directory 授予对IIS APPPOOL \\ DefaultAppPool的数据库访问权限 - Grant database access for IIS APPPOOL\DefaultAppPool 获取当前登录的用户 IIS 返回 DefaultAppPool - Get current logged in user IIS returning DefaultAppPool IIS权限:“每个人”都可以使用,但是IIS DefaultAppPool不起作用? - IIS Permissions: 'Everyone' works, but IIS DefaultAppPool doesn't? 需要管理员组中的DefaultAppPool才能运行vb脚本 - Need DefaultAppPool in the administrators group to run vb script 在IIS 7中,APP Pooliner / DefaultAppPool用户是EVERYONE用户组的一部分吗? - In IIS 7, Is APP Pool/DefaultAppPool user part of EVERYONE user group? 授予对IIS APPPOOL \\ DefaultAppPool的SQL Server数据库访问权限 - Granting sql server database access to IIS APPPOOL\DefaultAppPool 从DefaultAppPool下运行msdeploy.exe会产生奇怪的行为 - Run msdeploy.exe from under DefaultAppPool produces weird behaviour 无论我做什么,继续“登录用户IIS APPPOOL \\ DefaultAppPool失败” - Keep getting “Login failed for user IIS APPPOOL\DefaultAppPool” no matter what I do 如何使用asp.net C#重启IIS 6的defaultAppPool? - How to restart IIS 6 's defaultAppPool using asp.net C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM