简体   繁体   English

以编程方式更改IIS 7应用程序物理路径

[英]Change IIS 7 application physical path programmatically

I want to change the physical path of an application running on my IIS 7 from another application that runs on my IIS . 我想从IIS上运行的另一个应用程序更改在IIS 7上运行的应用程序的物理路径。 I tried to do this via appcmd.exe. 我尝试通过appcmd.exe执行此操作。 However, this seems to be impossible due to lack of authorization from the asp.net application. 但是,由于缺少asp.net应用程序的授权,因此这似乎是不可能的。

That is basically what I'm trying to do 那基本上就是我要做的

   private static string Execute(string IISAppName, string NewIISPath)
   {
        var winPath = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
        var appcmdPath = Path.Combine(winPath, "system32", "inetsrv/appcmd.exe");

        var arg = "set app /app.name:\"" + IISAppName + "\" /[path='/'].physicalPath:" + NewIISPath;

        ProcessStartInfo startInfo = new ProcessStartInfo(appcmdPath, arg)
        {
            WindowStyle = ProcessWindowStyle.Hidden,
            RedirectStandardOutput = true,
            UseShellExecute = false,
            CreateNoWindow = true
        };

        Process process = Process.Start(startInfo);
        var textResult = process.StandardOutput.ReadToEnd();
        process.WaitForExit();
        return textResult;
   }    

textResult is an empty string. textResult是一个空字符串。

Any ideas? 有任何想法吗?

The AppPool for the ASP.NET site would have to be configured to run as a user with admin privilege on the box to execute that script. 必须将ASP.NET站点的AppPool配置为以具有管理员特权的用户身份运行,才能执行该脚本。 In almost all cases, this is a bad idea for security reasons. 在几乎所有情况下,出于安全原因,这都是一个坏主意。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM