Execute bat file in asp.net localhost - asp.net

Hi i am trying to execute bat file in asp.net. it runs in developer/IIS Express but dosnt in IIS. i think there something with permissions. Thanks.
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo = new ProcessStartInfo(#"C:\Data\MyFile.bat");
myProcess.Start();
myProcess.Close();

Check your permissions on the C:\Data\ folder. Make sure the IIS_IUSRS has read and execute permissions.
otherwise If an application pool is configured to run using the Application Pool Identity feature then a "synthesised" account called IIS AppPool\<pool name> will be created on the fly to used as the pool identity. In this case there will be a synthesised account called IIS AppPool\DefaultAppPool created for the life time of the pool. You can add this account to C:\Data\ folder permissions to grant access to your application.

Related

ASP.NET application and user it is running under

I have multiple applications on a IIS server. How can I set one particular application to run as user 'appuser' and all uploaded files to be saved by as this user. ASP.NET
Every single IIS application run under some so-called application pool. The application pools have default identity (App Pool Identity in newer IIS, NETWORK SERVICE in older IIS). You can also set application pool to have custom identity by specifying user credentials.
However it seems like an overkill to run application under specific user if the only thing you require is to set specific owner for files being created - so I'd rather just force file owner after the file was created instead of changing application pool identity.
See Getting / setting file owner in C#
how to do that.
UPDATE
If you have to write to folder which is restricted to (yourspecialusername) I recommend this approach:
1) Dump file to temp files folder
2) Copy your file to shared folder under the (yourspecialusername) - see - Start a .Net Process as a Different User
3) Wait for Process in 2) to exit and delete temp file

Accessing Local Service

Hope you can help.
We have a web application (.NET 2.0) that has some custom code that is used to poke a windows service when a file is uploaded. We issue a command using the following code:
Dim serviceName As String = "Processor Service 1.0"
sc = New ServiceController(serviceName)
sc.ExecuteCommand(200)
Running this code in a standalone app works fine but when running through website throws an access denied error. Code works fine in IIS 6.
We are using an application pool with a user and is in Admin group. I figure it's something to do with IIS but now sure what.
Hoping you guys can help.
Thanks
The permissions that are needed to interact with local services are pretty high. Your asp.net app is likely running as anonymous (local account IUSR), or the "application pool identity". You would have setup your app in IIS (app pool) to use a different account with greater permissions.
In IIS Admin, under the section "IIS", "Authentication", you need to enable a stronger authentication method. If "Anonymous Authentication" is the only one enabled, then check the settings "Edit" to see if it is running as IUSR or "Application pool identity". This is where you determine, or set, the account (and permission set) that your ASP.NET app is using.
I feel that I should strongly warn against elevating the permissions for IIS and anonymous users. This would create a very dangerous back-door into your system. The suggestion from bgs264 is a very good one: make a separate service (or scheduled process) that watches for file uploads, or modify the existing service to use the file-watcher to monitor for uploaded files. It could run under a higher permission set and would be much more isolated from your IIS. Granting admin permissions to IIS or its app pools, is just like begging for trouble.

What's the account to run Asp.NET application?

I have an asp.NET web app which application pool is .NET 2.0
I have following code to generate PDF file(with crystal report):
Response.ContentType = "application/pdf"
Response.WriteFile(PDFFileName)
it puts a pdf file on a specific folder.
It's working fine for long time. but after network changed, it is not working anymore. I guess it is permission issue. With about code, which account should have the write permission on the folder? Is it ASPNET Account?
could be ASPNET or could be NETWORK Service
it depends on what your app pool settings are set to for the user account.
Go into IIS manager and find the app pool your application is running on and see what the account setting is. This is what your website will run under and thus the folder you are writing too will require the account added to the permissions.

What Windows account does an ASP.NET 4 application run under?

What Windows user account does an ASP.NET MVC 4 app run under?
When I deploy my MVC app to IIS 7, it isn't writing exceptions to the log file. I stepped into the source while the application was deployed and found that it didn't have rights/the required privileges to write to the log file.
So, I want to grant more privileges to the account that the app is running under.
Go to:
IIS > Application Pools > (right-click) the Application Pool > Advance Settings... > (Under Process Model) Identity.
You can change it if you want. It should be ApplicationPoolIdentity.
That's just depend on what's the path you're going to write. For example, if you're deploying your asp.net website use default "Network Service" account, you should grant the right permission to it.
To get the account you're currently using, you can check the identity of the app pool for your website.
Using IIS 8.5?
The ApplicationPoolIdentity is a member of the IIS_IUSRS group. If you need to give the app direct access to the file system set the ACLs for IIS_IUSRS.
However, exposing the file system to the web required very careful consideration.

Give IIS permissions to run as administrator (in order to run from web .exe that write to folders)

I have an API in mvc4 that call to .exe file via 'Process' class.
This .exe using log4net, and run another .exe that export files to directory and subdirectories. In the end of the process, the .exe post to http API.
Process p = new Process();
p.StartInfo.FileName = ConfigurationManager.AppSettings["ExtractToolPath"];
p.StartInfo.Arguments = this.strcommand;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.Verb = "runas";
p.StartInfo.RedirectStandardInput = true;
p.Start();
string s = p.StandardOutput.ReadToEnd();
p.WaitForExit();
String 's' returns with "" (blank string).
The s paramter get what was printed to the Console window. And I did a print in the begining of the .exe, therefor I know it even not started the process.
Important: When I remove the log4net logger, the 's' parameters gets some output, but it's failes when tring to do any command that requieres write permissions.
I tried to give the IIS executable permission, and immpersonation with admin username and password. I did my directories 'share' to everyone. Nothing helped.
Did you try setting the application pool identity to an administrator? Or giving write permissions on the directory to the application pool identity?
The credentials used to do the writing are the ones in the application pool identity.
I had a similar context when an ASP.NET Core application deployed on IIS had to start a process (with some parameters) from Program Files (clearly outside web application folder) which output data in some directory within a user profile (also, outside web application folder).
When run from command prompt, the command required elevation (User Account Control).
In order to make it run from IIS:
IIS AppPool\YourPool had to be able to write into output directory
I have created a bat file within Web application directory that contained the command to be issued
IIS AppPool\YourPool was not included within Administrators user group
This was tested on a Windows 7 x64.

Resources