[英]Unlock section in applicationHost.config programmatically
I have checked ServerManagaer class and it gives a lot of functionality to work with IIS, it also contains methods to update values in applicationHost.config file, but I can't fine any way to unlock sections there. 我已经检查了ServerManagaer类,它提供了许多与IIS一起使用的功能,它还包含更新applicationHost.config文件中的值的方法,但是我无法以任何方式解锁那里的部分。
For example for that purpose appcmd.exe unlock config command is used. 例如,为此目的使用appcmd.exe unlock config命令。 I need to do the same programmatically.
我需要以编程方式执行相同的操作。
To my knowledge you can't perform lock/unlock action using ServerManager but still you can execute appcmd.exe programatically to achieve the desired result: 据我所知,您无法使用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();
As already said you can run appcmd process. 如前所述,您可以运行appcmd进程。 But just a hint that if you don't console to popup you can redirect the output.
但这只是一个提示,如果您不控制台弹出窗口,则可以重定向输出。
Here is the code from MSDN 这是来自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.