2

I have created an WebApi project in which I am calling a exe namely Latlong2XY.exe which takes input file and outputfile as paramreter. And returning me a .txt as output file. When I am executing the application from VS2012 IDE it is successfully creating the required txt file. However when I publish the same application in IIS and running it then it is not able to create the txt file.

it appears IIS Express is creating the txt file while IIS is not.

It appears to be some permission issue. But does not have any clue what to do. My code is:

        int exitCode;
        // Prepare the process to run
        ProcessStartInfo start = new ProcessStartInfo();
        // Enter in the command line arguments, everything you would enter after the executable name itself
        start.Arguments = @"D:\RFD\InputFile.txt D:\RFD\Results.txt";
        // Enter the executable to run, including the complete path
        start.FileName = @"D:\RFD\Latlong2XY.exe";
        // Do you want to show a console window?
        start.WindowStyle = ProcessWindowStyle.Hidden;
        start.CreateNoWindow = true;

        // Run the external process & wait for it to finish
        using (Process proc = Process.Start(start))
         {
            proc.WaitForExit();

            // Retrieve the app's exit code
            exitCode = proc.ExitCode;

        }

IIS settings are :

Windows Authentication: disabled; Forms Authentication: disabled; Anon auth: enabled; .Net Impersonation: disabled.

i'm using ASP.NET v4.0 Application pool.

Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67

2 Answers2

0

You will need to give the application directory (where the hosted files are on the machine) elevated privileges. (Typically C:\inetpub\wwwroot\YourAppName)

Give the user 'IIS_USR' or something close to that name write access to the folder.

Jason Loki Smith
  • 428
  • 3
  • 12
0

Yes., When you perform these kind of operations from "Visual Studio IDE" It will work because IDE has minimum permission to control your IO operations for (System.Diagnostics.Process.Start).

When you go to Web application hosting from IIS, unfortunately IIS doesn't have these permission settings in built. So you need to set permissions to perform windows native operations.

Note : By using this you are gonna provide your system(server) username and password as encrypted.

You can set windows authentication permission in the Web Config Using Aspnet_setreg.exe. Which will be available in internet with usage notes.

Add the below line in your webconfig:

<authentication mode="Windows"/>

<identity impersonate ="true"  userName="registry:HKLM\SOFTWARE\YourAPPName\ASPNET_SETREG,userName" password="registry:HKLM\SOFTWARE\YOURAPPNAME\ASPNET_SETREG,password"/>

The similar problem i have faced during development of "windows service Re-Start from web". The Same permission issues i have resolved and got worked on this way.

This answer may not be perfect. But this is also one way to achieve the solution

RajeshKdev
  • 6,365
  • 6
  • 58
  • 80