简体   繁体   English

单击Web表单中的链接按钮,下载/打开.exe文件

[英]Download/Open .exe file on click of link button in web form

I have a link button as below: 我有一个链接按钮,如下所示:

 <asp:LinkButton ID="Import" runat="server" Font-Size="Small" Visible="true">Import</asp:LinkButton>

On click of this link button,I want the user to download a .exe file if it is not already present in user's computer or open the existing .exe file if it is already present in the user's computer. 单击此链接按钮时,如果用户的计算机中不存在.exe文件 ,我希望用户下载该文件。如果用户的计算机中不存在该文件,请打开现有的.exe文件

I tried this: 我尝试了这个:

string str = @"C:\Users\Documents\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe";
    Process process = new Process();
    process.StartInfo.FileName = str;
    process.Start();

This works fine in my local machine but the .exe cannot be accessed from the web page once its hosted.I think its possibly because of website security issues (correct me if I am wrong) that it doesn't allow the user to access the .exe location. 这在我的本地计算机上运行良好,但是托管后无法从网页访问。我认为这可能是由于网站安全问题(如果我错了,请纠正我),它不允许用户访问.exe位置。

This was a little bit of background info. 这是一些背景信息。

My question is how do I modify this so that the user can download the .exe to his own machine (since I am not being able to access otherwise) and if he has done so once,the next time he clicks on the link button it opens his previously downloaded .exe ? 我的问题是我该如何修改它,以便用户可以将.exe下载到自己的计算机上(因为我无法以其他方式访问),并且如果他这样做了,则下次单击链接按钮时打开他先前下载的.exe吗?

If you want a user to download your application(.exe) you should include it in the web project, and the link should reference the file by a relative path. 如果要用户下载应用程序(.exe),则应将其包含在Web项目中,并且链接应通过相对路径引用文件。

A browser will never let a site run an .exe file (after it was downloaded), just by clicking a link, this is a big security risk. 浏览器永远不会让站点运行.exe文件(下载后),仅通过单击链接,这会带来很大的安全风险。

How to launch an EXE from Web page (asp.net) 如何从网页(asp.net)启动EXE

Refer this page. 请参阅此页面。 We faced similar problem and then agreed on below solution. 我们遇到了类似的问题,然后就以下解决方案达成了一致。 On click allow it will be downloaded and option for running will come. 单击“允许”将被下载,并提供运行选项。 This will be browser dependent. 这将取决于浏览器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM