Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Denied starting process from ASP.NET website

I have an ASP.NET MVC4 website where I'm trying to execute a process on the server. The code is as follows:

ProcessStartInfo startInfo = new ProcessStartInfo()
{
    FileName = ExeLocation,
    Arguments = string.Format("\"{0}\"{1}", ScriptLocation, Arguments),
    UseShellExecute = false,
    RedirectStandardOutput = true,
    RedirectStandardError = true,
    WorkingDirectory = AppDir,
    CreateNoWindow = true,
    UserName = ExeUsername,
    Password = ExePassword,
    Domain = ExeDomain
};

using (Process process = Process.Start(startInfo))
{
    using (StreamReader reader = process.StandardOutput)
    {
        output = reader.ReadToEnd();
    }
    using (StreamReader reader = process.StandardError)
    {
        error = reader.ReadToEnd();
    }
    process.WaitForExit();
    if (process.ExitCode != 0)
    {
        throw new Exception(string.IsNullOrEmpty(output) ? error : output);
    }
}

This works fine on my local machine in Visual Studio, but when I deployed to my server (W2K12) I get the following error:

Access is denied   
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)

I have the account referenced by ExeUsername in both the Administrators and IIS_IUSRS groups on the server.

The application pool is running as a different account (hence the need to assign a specific account to run the process) which is also a member of Administrators and IIS_IUSRS on the server.

When I log into the server and run a command prompt as ExeUsername, I am able to execute the process, so the issue must be related to executing from IIS.

What else could be blocking this access?

like image 503
Paul Avatar asked Nov 07 '22 18:11

Paul


1 Answers

  1. Right click on applicationpool
  2. Click on advanced setting
  3. Identity
  4. Custom Account
  5. Set username and password

If you have domain be careful use domain\username for username
and also access to folder of deployment.

like image 74
hassan.ef Avatar answered Nov 14 '22 23:11

hassan.ef