如何通过ASP.net运行EXE文件?

时间:2012-05-13 21:23:17

标签: c# asp.net

我在C#中为ASP.NET创建了一个页面来运行exe文件。我使用以下代码创建了一个按钮和一个事件:

        ProcessStartInfo info = new ProcessStartInfo(@"C:\inetpub\wwwroot\Share\myfile.exe");
        info.UseShellExecute = false;
        info.RedirectStandardInput = true;
        info.RedirectStandardError = true;
        info.RedirectStandardOutput = true;

        //info.UserName = dialog.User;
        info.UserName = "username";
        string pass = "MY pass";
        System.Security.SecureString secret = new System.Security.SecureString();
        foreach (char c in pass)
            secret.AppendChar(c);
        info.Password = secret;
        Process.Start(info);   

我是从编译器执行的,它运行正常,但是当我在localhost中发布我的项目时,我没有动作。有什么问题?

3 个答案:

答案 0 :(得分:3)

你尝试了什么? 这可能是权利问题。默认情况下,您的网站不应该能够执行外部可执行文件,因为这将是一个严重的安全风险。也许你的问题有一个不同的解决方案,不涉及运行外部程序?

无论哪种方式,我强烈建议不要直接从您的网站运行可执行文件。如果你真的必须运行该程序,也许你可以写一个简单的Windows服务,它可以接收一条消息(通过WCF?),然后在隔离的环境中执行你的程序。

答案 1 :(得分:0)

在asp.net中执行(运行)应用程序,我使用了这个方法:

1)查看其他网站上的代码:

2)在 web.config 中," assemblyIdentity "领域,我已经添加了"模仿"参数,像这样:

更改
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>

<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" impersonate="true" userName="myuser" password="123123"/>

(首先,您可能需要为该文件夹设置sql / windows用户和密码权限。)

2)然后我在我的asp.net中使用了命令(也许也使用了asp 2.0):

System.Diagnostics.Process.Start("C:\\inetpub\\my_application.exe" , "with-any-parameters");

答案 2 :(得分:-1)

您可以尝试

System.Diagnostics.Process.Start(MapPath("Windowscalculater.exe"))

Dim p As New Process
p.StartInfo.FileName = MapPath("Windowscalculater.exe")
p.Start()