【问题标题】:Unlock section in applicationHost.config programmatically以编程方式解锁 applicationHost.config 中的部分
【发布时间】:2012-01-21 02:06:59
【问题描述】:

我检查了 ServerManagaer 类,它提供了很多与 IIS 配合使用的功能,它还包含更新 applicationHost.config 文件中值的方法,但我无法通过任何方式解锁那里的部分。

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

【问题讨论】:

标签: c# .net iis


【解决方案1】:

如前所述,您可以运行 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

【讨论】:

    【解决方案2】:

    据我所知,您无法使用 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();
    

    【讨论】:

      猜你喜欢
      • 2011-08-08
      • 2011-10-21
      • 2015-06-09
      • 1970-01-01
      • 1970-01-01
      • 2012-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多