繁体   English   中英

以编程方式解锁applicationHost.config中的部分

[英]Unlock section in applicationHost.config programmatically

我已经检查了ServerManagaer类,它提供了许多与IIS一起使用的功能,它还包含更新applicationHost.config文件中的值的方法,但是我无法以任何方式解锁那里的部分。

例如,为此目的使用appcmd.exe unlock config命令。 我需要以编程方式执行相同的操作。

据我所知,您无法使用ServerManager执行锁定/解锁操作,但仍然可以以编程方式执行appcmd.exe来获得所需的结果:

System.Diagnostics.Process appCmdProc = new System.Diagnostics.Process();
appCmdProc.StartInfo.FileName = "Path-to-Directory\appcmd.exe";
appCmdProc.StartInfo.Arguments = "unlock config /section:sectionName";
appCmdProc.Start();

如前所述,您可以运行appcmd进程。 但这只是一个提示,如果您不控制台弹出窗口,则可以重定向输出。

这是来自MSDN的代码

// Start the child process.
 Process p = new Process();
 // Redirect the output stream of the child process.
 p.StartInfo.UseShellExecute = false;
 p.StartInfo.RedirectStandardOutput = true;
 p.StartInfo.FileName = "Write500Lines.exe";
 p.Start();
 // Do not wait for the child process to exit before
 // reading to the end of its redirected stream.
 // p.WaitForExit();
 // Read the output stream first and then wait.
 string output = p.StandardOutput.ReadToEnd();
 p.WaitForExit(); 

更多详细信息,请点击这里

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM