【发布时间】:2021-07-31 18:26:29
【问题描述】:
我想开发一个控制台应用程序以获取截至check the status of IIS Application Pool 的 IIS 应用程序池状态。
我得到了类似的代码,并且在 DirectoryEntry 类中,当我添加给定的代码行时出现错误。(我只在该类中添加了以下行)
appPools = new DirectoryEntry("IIS://" + ServerName + "/W3SVC/AppPools", UName, Pwd).Children;
谁能让我知道我应该包含哪些包以及我应该包含更多以消除错误。
我在 DirectoryEntry 类中遇到的错误:
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# 新手,请大家帮帮我。
谢谢。
【问题讨论】:
-
请edit您的问题包含您文件的完整源代码。看起来你把这行代码放在了不属于它的位置。
-
@Progman 已编辑。
-
您忘记了
DirectoryEntry类中字段appPools的类型。看起来应该是DirectoryEntries appPools = new Directory....。此外,您正在定义一个名为DirectoryEntry的新类,同时还要创建一个DirectoryEntry的实例。不确定您要对DirectoryEntry类做什么,但已经有一个类System.DirectoryServices.DirectoryEntry。很可能您只想在那里删除您的DirectoryEntry类。 -
@Progman 我提到stackoverflow.com/questions/37613513/… 有一个名为 DirectoryEntory 的类。这就是我使用它的原因,但我不明白该类的目的。如果我删除 DirectoryEntry 类,它会损害其中的功能program.cs?或者如果我删除了 DirectoryEntry 类,我必须如何修改 program.cs 类?
-
当我删除 DirectoryEntry 类时,我仍然得到与上面提到的相同的错误,"if (appPool.Name.ToString().ToLower().Trim() == DT. Rows[i]["AppPoolSrvName"].ToString().ToLower().Trim())"。如果我从 program.cs 类的配置文件中删除获取服务器凭据和服务器名称的代码段,那么如何我修改它?(比如没有获取 Uname 和 Pwd,我可以从 appsettings.json 文件中获取进程名称吗?如果可能的话,如何实现它)或者有没有其他方法可以做到这一点?请问帮帮我,我真的很困惑