Search code examples
c#asp.netiis-7application-poolapplicationpoolidentity

Running command from ASP.NET App Pool Identity


I am running an executable process from my ASP.NET application when a user clicks a button. This process creates several files and serves them up to the end-user. I can't really see what the process is or isn't doing, but it didn't work until I specified the admin user as the application pool identity on the server. I am using IIS7.

 using (var proc = new Process())
 {
    proc.StartInfo.FileName = Server.MapPath("~/Testing/Demo/MyExe.exe");
    proc.StartInfo.Arguments = String.Format("\"{0}\"", commandFilePath);
    proc.StartInfo.UseShellExecute = true;
    proc.Start();
    proc.WaitForExit();
 }

I'm assuming that this is generally a bad thing to do. Can you give me insight into what needs to be done in order to enable this for the normal ApplicationPoolIdentity account?

Thanks!


Solution

  • Thank you all for your help. All I needed to do was set the StartInfo.WorkingDirectory to somewhere that I was able to write.

            using (var proc = new Process())
            {
                proc.StartInfo.FileName = Server.MapPath("~/Testing/Demo/MyEXE.exe");
                proc.StartInfo.Arguments = String.Format("\"{0}\"", commandFile);
                proc.StartInfo.WorkingDirectory = savePath;
                proc.Start();
                proc.WaitForExit();
            }
    

    This causes the temp files to be written to a non-system folder and thus does not need any elevated permissions for the application pool.