Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
726 views
in Technique[技术] by (71.8m points)

iis 7.5 - Run console application (.exe) from within ASP.NET application (IIS 7,5)

I have an ASP.NET application on Windows 2008 R2 (.NET Framework 4.0, IIS 7.5) and I want to run a console application when I click a button on a web page. Here is the code:

protected void btnUpdate_Click(object sender, EventArgs e)
    {
        string fileLocation = @"D:DTDocsApp_CodeLoadDTDocsXML.exe";
        ProcessStartInfo oStartInfo = new ProcessStartInfo();
        oStartInfo.FileName = fileLocation;
        oStartInfo.UseShellExecute = false;
        Process.Start(oStartInfo);
}

When I run ASP.NET application from within Visual Studio 2010 (with its internal IIS), the console application run Ok. But when I run the ASP.NET application outside the VS 2010, I haven't an error but the console application doesn't make his job (it must create an xml file on the disk). I think the problem is the configuration of IIS 7.5, I don't know exact to which account I must give access rights to the folders involved in my console application. In IIS 7.5, I set Physical Path Credential for Specific User = my windows account, but that not solve the problem. Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just to add to the other 2 answers - Do you really need to run an exe from your webserver?

I've had to do it in the past and it's almost always the option of last resort - It weakens your security considerably (Now all someone has to do to run executables on your system is find a single flaw in your code) and has a whole host of other problems (the webserver isn't "logged on" to the server so it doesn't have a desktop, impersonation is a real pain in the a$$ to get working properly (assuming you're going to run the executable with different permissions to the webserver), etc.

If there's any other way to accomplish your goal, it'll almost certainly be simpler.

An option we went for was to have a new app with a WCF endpoint that the webserver can communicate with. So, when someone pushes the button, the WS call's our app via WCF and tells it to run various commands. This way, you've got:

  • Clean seperation between web and console code.
  • A dodgy console app won't take down the webserver & vice-versa
  • If the console app is long-running, this allows you to stagger your releases for website/console app so that you don't kill the app mid-execution just because you need up upodate some CSS and publish.
  • Huge security benefits - web server can't run executables even if compromised.
  • The WCF app will be able to closely examine requests to decide if they're valid before execution.

Be aware that however you do it, if someone malicious works out what's going on and can kick off the process, they could probably DoS you with almost zero effort - Make sure that this method is locked down TIGHT.

Edit: having read your comments above, I think you're hitting the "desktop" issue. When launching an executable from the server, the app will never be visible to the logged on user as the logged on user's desktop isn't accessible from IIS and vice-versa. This is very similar to the issue of having a GUI on a windows service.

This may also be of interest.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...