简体   繁体   English

访问被拒绝从远程计算机读取Perfmon计数器(Asp.Net)

[英]Access denied reading Perfmon counters from a remote machine (Asp.Net)

I'm trying to create a simple Asp.Net page to read Perfmon counters from a remote machine. 我正在尝试创建一个简单的Asp.Net页面来从远程计算机读取Perfmon计数器。

When I run the page using the Visual Studio development web server all is well, however when I attempt to run the same page when its hosted on IIS I get an access denied error on the line that instantiates the Perfmon counter: 当我使用Visual Studio开发Web服务器运行页面时一切都很好,但是当我在IIS上托管时尝试运行同一页面时,我在实例化Perfmon计数器的行上获得了访问被拒绝错误:

PerformanceCounter freeSpaceCounter = new PerformanceCounter("LogicalDisk", "Free Megabytes", "D:", "RemoteMachine12");

This is the exception I get: 这是我得到的例外:

Exception Details: System.ComponentModel.Win32Exception: Access is denied

I've tried using both anonymous access (with myself as the anonymous user) and Integrated Windows Authentication - both dont work. 我尝试过使用匿名访问(我自己作为匿名用户)和集成Windows身份验证 - 两者都不起作用。 Clearly some other account is be used to read the PerfMon counters (like the ASPNET account). 显然,其他一些帐户用于读取PerfMon计数器(如ASPNET帐户)。 How do I get my page to access the PerfMon counters using my account rather than that account? 如何使用我的帐户而不是该帐户访问我的页面以访问PerfMon计数器?

The problem you have here is that IIS runs under the context of a local account (by default). 您遇到的问题是IIS在本地帐户的上下文中运行(默认情况下)。 This local account doesn't exist on the remote machine, and so can't connect to get the performance counters. 远程计算机上不存在此本地帐户,因此无法连接以获取性能计数器。 When you use the VS development web server it runs under your own local account and so everything works. 当您使用VS开发Web服务器时,它在您自己的本地帐户下运行,因此一切正常。

If you're in a domain environment you can configure the IIS application pool to run as a domain account with access to both machines, and everything will work, however you may want more control over this. 如果您处于域环境中,则可以将IIS应用程序池配置为可以访问这两台计算机的域帐户运行,并且一切都可以正常运行,但是您可能需要对此进行更多控制。

You could either use basic authentication, with the application configured for impersonation (or if you're using IIS7 having the pool configured to run under the authenticated account) or you impersonate just before you read the counter. 您可以使用基本身份验证,将应用程序配置为模拟(或者如果您使用IIS7将池配置为在经过身份验证的帐户下运行),或者在您阅读计数器之前进行模拟。

There are a couple of ways to impersonate - the safest is to configure IIS to use integrated authentication and then wrap the call up 有两种方法可以模拟 - 最安全的方法是将IIS配置为使用集成身份验证,然后打包调用

PerformanceCounter freeSpaceCounter = null;
using (((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate())
{
    freeSpaceCounter = new PerformanceCounter("LogicalDisk", 
                               "Free Megabytes", "D:", "RemoteMachine12");
}

If you don't want authentication then you'll have to configure the app pool, or hard code a username and password in your application - this should be the last resort, see KB306158 如果您不想要身份验证,则必须配置应用程序池,或者在应用程序中硬编码用户名和密码 - 这应该是最后的选择,请参阅KB306158

From MSDN: 来自MSDN:

To read performance counters in Windows Vista, Windows XP Professional x64 Edition, or Windows Server 2003, you must either be a member of the Performance Monitor Users group or have administrative privileges. 要在Windows Vista,Windows XP Professional x64 Edition或Windows Server 2003中读取性能计数器,您必须是Performance Monitor Users组的成员或具有管理权限。

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

相关问题 什么perfmon计数器可用于识别ASP.NET瓶颈? - What perfmon counters are useful for identifying ASP.NET bottlenecks? ASP.net应用程序的最佳perfmon计数器是什么? - What are the best perfmon counters for an ASP.net application? ASP.NET MVC:创建性能计数器时拒绝请求的注册表访问 - ASP.NET MVC: Requested registry access denied when creating performance counters 从ASP.NET查询远程计算机时WMI访问被拒绝错误 - WMI access denied error when query remote computer from ASP.NET 在asp.net中拒绝访问 - Access is denied in asp.net 如何从ASP.NET Web应用程序访问perfmon(Windows Server 2008)原始收集的数据? - How can one access perfmon (windows server 2008) raw collected data from an ASP.NET web application? 无法从远程计算机测试asp.net Web服务 - not able to test asp.net web service from remote machine 在Microsoft Azure中访问ASP.NET Web App的性能计数器 - Access performance counters for ASP.NET Web App in Microsoft Azure 从ASP.NET网站访问拒绝启动过程 - Access Denied starting process from ASP.NET website 从ASP.Net应用程序对Directory.CreateDirectory的访问被拒绝 - Access denied on Directory.CreateDirectory from ASP.Net application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM