从 ASP.NET 应用程序运行外部进程时出现问题。
该过程如下运行:
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public static WebResult generateSomething(string language)
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.CreateNoWindow = true;
psi.ErrorDialog = false;
psi.WorkingDirectory = Environment.CurrentDirectory;
psi.FileName = String.Format("\"{0}\"", Path.Combine(appDir, Properties.Settings.Default.PATH_TO_APP_TEXT));
psi.Arguments = arguments.ToString();
modeller.log.Info("Arguments: " + psi.Arguments);
var outputText = new StringBuilder();
int exitCode;
var result = new WebResult();
using (Process process = new Process())
{
process.StartInfo = psi;
process.OutputDataReceived += (sendingProcess, args) => { outputText.Append(args.Data); };
process.ErrorDataReceived += (sendingProcess, args) => { outputText.Append(args.Data); };
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
exitCode = process.ExitCode;
}
string outText = outputText.ToString();
在进程完成(成功与否)并且方法离开 ASP.NET IIS 会话后立即结束,因此任何通过 cookie 的身份验证上下文都会中断。
任何人都可以帮助解决这个问题吗?提前致谢