简体   繁体   English

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

[英]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(); 

More details see HERE 更多详细信息,请点击这里

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

相关问题 Applicationhost.config未更新 - Applicationhost.config not updated applicationhost.config中的位置路径未映射到程序集 - Location path in applicationhost.config not mapping to assembly C# applicationHost.config 未找到但存在 - C# applicationHost.config not found but exists IIS CLI为我的项目生成带有site的applicationhost.config - IIS CLI generate applicationhost.config with site for my project Microsoft.Web.Administration-ApplicationHost.Config中带有httpError的NullReferenceException - Microsoft.Web.Administration - NullReferenceException with httpErrors in ApplicationHost.Config 由于applicationHost.config无效,.Net构建失败 - .Net build is failing due to invalid applicationHost.config 如何将IIS ApplicationHost.config文件解析为.Net对象? - How to parse the IIS ApplicationHost.config file into .Net objects? ASP.NET 核心 web.config requestFiltering 不覆盖 applicationhost.config - ASP.NET Core web.config requestFiltering not overriding applicationhost.config 初始化 applicationhost.config 文件失败。 找不到 IIS Express - Initializing the applicationhost.config file failed. Cannot find IIS Express applicationHost.config 错误:由于 IIS 共享配置的权限不足,无法写入配置文件 - applicationHost.config Error: Cannot write configuration file due to insufficient permissions with IIS shared configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM