0

I want to change the physical path of an application running on my IIS 7 from another application that runs on my IIS . I tried to do this via appcmd.exe. However, this seems to be impossible due to lack of authorization from the asp.net application.

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.

Any ideas?

1 Answers1

0

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. In almost all cases, this is a bad idea for security reasons.

chief7
  • 14,263
  • 14
  • 47
  • 80