如何修复错误,名称''在c#的当前上下文中不存在

How to fix the errors,name ' ' does not exist in the current context in c#

我想开发一个控制台应用程序以获取截至 的 IIS 应用程序池状态。

我在 DirectoryEntry class 中得到了类似的代码,当我添加给定的代码行时出现错误。(我只在 class 中添加了以下行)

 appPools = new DirectoryEntry("IIS://" + ServerName + "/W3SVC/AppPools", UName, Pwd).Children;

有人可以让我知道我应该包含哪些包以及我应该包含哪些包以消除错误。

我在 DirectoryEntry 中遇到的错误 class-:

         name 'appPools' does not exist in the current context.
         name 'Children' does not exist in the current context.
         the type or namespace name 'Pwd' could not be found(are u missing a using directory or an assembly reference)
         the type or namespace name 'ServerName' could not be found(are u missing a using directory or an assembly reference)
         the type or namespace name 'UName' could not be found(are u missing a using directory or an assembly reference)
         the modifier 'new' is not valid for this item
         identifier expected

有人可以帮助我吗,因为我是 c# 的新手。

谢谢。

你应该安装 NuGetSystem.DirectoryEntry 然后添加一个 usingSystem.DirectoryServices.DirectoryEntry 然后它应该编译。

关于 UName & Pwd 你只需要提供代表你的用户名和密码的字符串。