我檢查了ServerManagaer類,它提供了很多使用IIS的功能,它還包含更新applicationHost.config文件中的值的方法,但我無法解決任何解鎖方法那裏的部分。以編程方式解鎖applicationHost.config中的節
例如爲此目的使用appcmd.exe 解鎖配置命令。我需要以編程方式執行相同的操作。
我檢查了ServerManagaer類,它提供了很多使用IIS的功能,它還包含更新applicationHost.config文件中的值的方法,但我無法解決任何解鎖方法那裏的部分。以編程方式解鎖applicationHost.config中的節
例如爲此目的使用appcmd.exe 解鎖配置命令。我需要以編程方式執行相同的操作。
前面已經說了,你可以運行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();
更多細節見HERE
據我所知,使用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();
參見[編程解鎖-IIS配置截面合的powershell](https://stackoverflow.com/questions/5717154/programmatically-unlocking-iis-configuration-sections-in-powershell)你也可以用c# – Dream