我有一个关于从 asp.net 网站启动外部应用程序的问题。现在我认为有适当的安全措施来防止这种情况,我知道这不是一个好的做法,但对于我正在开发的 Intranet 站点来说,能够做到这一点将非常方便。
到目前为止,如果我在本地运行我的服务器(在调试中),我已经找到了可以启动外部应用程序的地方,那么它工作正常。当我将文件发布到我的网络服务器时,它不再起作用。我知道我的文件路径会有所不同,但我如何检查本地文件是否存在?或者我可以吗?
所以这是我的代码:
//the actual launch button on the page
protected void btnLaunchTnet_Click(object sender, EventArgs e)
{
    string tnetpath = "c:\path\tnet.exe";      
    RunProcess(tnetpath, "");
}
private void RunProcess(string cmd, string arguments)
{
    System.Diagnostics.Process p;
    p = new System.Diagnostics.Process();
    p.StartInfo.FileName = cmd;
    if (arguments.Length > 1)
    {
        p.StartInfo.Arguments = arguments;
    }
    p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    p.StartInfo.RedirectStandardOutput = false;
    p.StartInfo.UseShellExecute = false;
    p.Start();
}
我还有一个快速的“检查此文件是否存在”,用于禁用或启用启动应用程序的按钮
private bool CheckFileExists(string filepath)
{
    FileInfo SetupPath = new FileInfo(filepath);
    return SetupPath.Exists;
}