簡體   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