Starting a process from ASP.NET - Why does the process immediately die?

后端 未结 3 1008
后悔当初
后悔当初 2020-12-11 12:38

I\'m attempting to start a Process from an ASP.NET C# application. My application communicates with this process via the process\' own API (this is a third-party program). I

相关标签:
3条回答
  • 2020-12-11 13:10

    It may not answer your question, but a fairly robust way of doing that sort of thing is e.g. having a Windows Service installed that runs with correct credentials and do some communication between web server and service e.g. via private message queue or even some Web API.

    This way you don't put yourself into a situation where you compromise your machine by giving the web process more rights than it really needs.

    You can imagine that if that what you do is possible in a web process an attack has a lot of possibilities to get elevated rights on the machine.

    0 讨论(0)
  • 2020-12-11 13:21

    My way to start a process from ASP .Net 4.0:
    1. A remoted class which actually starts the process ( it starts Adobe Reader in command line to print a PDF)
    2. A systray application as the host for the remote object
    3. An webservice which runs under .Net 2.0 and under a specific user, as a client for the remote object
    4. The ASP .Net 4.0 website calls the webservice method

    When a process is started from ASP .Net it "hangs". I can see it in Task Manager, but it does nothing, so this was the only solution I found. You can host the remote object in a console application or an windows service. WCF would be another good option to remoting, but I didn't try it, yet.

    0 讨论(0)
  • 2020-12-11 13:32

    I don't know of any specific way to set the process user rights, but you can see if the reason for immediate exit is within the process itself, say throwing exception due to limited rights.

    Use StartInfo to get the process output streams:

    pInfo.StartInfo.RedirectStandardInput = true;
    pInfo.StartInfo.RedirectStandardOutput = true;
    pInfo.StartInfo.RedirectStandardError = true;
    pInfo.StartInfo.ErrorDialog = false;
    

    After starting the process you can read it like this:

    StreamReader sOut = pInfo.StandardOutput;
    StreamReader sError = pInfo.StandardError;
    string standardResult = sOut.ReadToEnd();
    string standardError = sError.ReadToEnd();
    
    0 讨论(0)
提交回复
热议问题