我的程序的基本思想如下:我有一个网页,在用户提供一些输入后运行 C# 程序。此 C# 程序输出一个字符串,然后将显示在不同的网页上。简而言之,我只想将这个字符串从一个网页传递到另一个网页,然后将其打印到页面上。然而事实证明这是非常困难的。这是我目前的尝试:
private ActionResult CallProgram(string path)
{
//some code from calling my C# program
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.FileName = @"\\WMRILTriageTool\Triage\callRunEXE\callRunEXE.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "-f " + path + " -d 0 -w 1";
using (Process exeProcess = Process.Start(startInfo))
{
output = exeProcess.StandardOutput.ReadToEnd(); //output saved to string
exeProcess.WaitForExit();
}
return RedirectToAction("Result?results=output"); //pass output to ActionResult
}
然后调用此 ActionResult 函数:
[ValidateInput(false)]
public ActionResult Result(string results)
{
ViewBag.Message = "Results";
ViewBag.toWrite = results;
return View();
}
如您所见,我尝试使用查询字符串,但这不起作用。我得到错误:
“从客户端检测到潜在危险的 Request.Path 值(?)”
为了解决这个问题,我尝试将以下内容放入 Web.config:
<system.web>
<httpRuntime requestPathInvalidCharacters="" requestValidationMode="2.0" />
<pages validateRequest="false" />
</system.web>
但它不起作用(仍然得到同样的错误)。总而言之,如何将我的字符串从 CallProgram 函数传递到 ActionResult 函数,然后再传递到另一个网页?这个看似简单的程序花费了我比我愿意承认的更长的时间。非常感谢您对此事的任何帮助。谢谢你。