简体   繁体   English

如何将Windows Forms应用程序与ASP.NET C#Web进行交互? C#

[英]How to interact windows forms app to asp.net c# web? C#

我正在用C#开发windows application 。我有一个用ASP.NET C#开发的网站,其中包含按钮desktop app当用户click此按钮时,他重定向到desktop app用户登录名并将视频从计算机上传到server 。但是我的问题是如何将windows app与asp.net C#Web应用程序进行交互。用户上传视频,然后在Web中显示通知。

IMO there are multiple approaches to this. IMO有多种解决方法。

  1. You can make the user download the EXE and then run the same 您可以让用户下载EXE,然后运行相同的文件
  2. If you know the location of the EXE on the user's machine, you can use JavaScript ActiveX object to execute it 如果知道EXE在用户计算机上的位置,则可以使用JavaScript ActiveX对象执行它
  3. You can register a URI scheme on the user's computer and when user clicks on the link the link (like myexe://exePathOrDescription ) the respective shell command will get executed thus running the executable (btw, this is how skype call buttons on web page and magnet torrent links work) 您可以在用户的​​计算机上注册URI方案,当用户单击链接时(例如myexe://exePathOrDescription ),相应的shell命令将被执行,从而运行可执行文件(顺便说一句,这是网页上的Skype调用按钮的方式)和磁力种子链接有效)

1. Download EXE and run the same This is the easiest approach where the user will click a link like <a href="/internalServer/unknownFile.exe">Do not run this file</a> 1.下载EXE并运行相同文件。这是最简单的方法,用户将单击<a href="/internalServer/unknownFile.exe">Do not run this file</a> and then he/she will be asked to save or run the file. 然后将要求他/她保存或运行文件。 The user can click on 'Run' and after download is completed, the application will be executed by the browser. 用户可以单击“运行”,下载完成后,浏览器将执行该应用程序。

2. If you know the path to file, you can use JavaScript 2.如果知道文件的路径,则可以使用JavaScript

var activeX = new ActiveXObject("WScript.Shell");
activeX.Exec("C:\\folder\\executable.exe");

Note: ActiveXObject is available on IE only. 注意: ActiveXObject仅在IE上可用。 For other browsers refer to the responses to this SO question 对于其他浏览器,请参考对此问题的答复

3. Register URI Scheme (btw, my favorite) Here you can create a utility application which will be needed to be downloaded and executed for once to register the URI scheme, or alternatively, you can add code to your application to register the URI scheme when the application is executed for the first time. 3.注册URI方案 (我最喜欢的btw)在这里,您可以创建一个实用程序应用程序,该程序将需要下载并执行一次以注册URI方案,或者,您也可以在应用程序中添加代码以注册URI方案。首次执行该应用程序时。

Then you can create links on your web page that start with your URI scheme (like myExeScheme://pathToExecutable_URLEncodedWillBeBetter ). 然后,您可以在网页上创建以URI方案开头的链接(例如myExeScheme://pathToExecutable_URLEncodedWillBeBetter )。 When the URI scheme is registered on user's machine, when the user clicks on the above link, the respective Shell command (defined during the creation of URI scheme) will be executed and thus your application will be executed. 在用户计算机上注册URI方案后,当用户单击以上链接时,将执行相应的Shell命令(在URI方案创建期间定义),因此将执行您的应用程序。

After the application is executed, the user can proceed with login and other tasks on the application. 执行该应用程序后,用户可以在该应用程序上继续登录和其他任务。

To register URI scheme refer to the responses to this SO question 要注册URI方案,请参考对此SO问题的回答


For second part: Uploading images from desktop Windows 第二部分:从桌面Windows上传图像

You can create a web service to which you will push image/video data encoded as Base64 string and then decoded on server after receiving. 您可以创建一个Web服务,将编码为Base64字符串的图像/视频数据推送到其中,然后在接收后在服务器上解码。 Now the string could be very large so you may need to upload the data in chunks like 1KB data in one request, and while doing so you will have to plan a strategy regarding how will you maintain the sequence of the data uploaded. 现在,字符串可能非常大,因此您可能需要在一个请求中以1KB数据的形式大块上载数据,并且在这样做的同时,您将必须制定有关如何维护上载数据顺序的策略。


3rd Part: How to show notification on web page 第三部分:如何在网页上显示通知

You can use JavaScript/JQuery/AJax to continuously check on server if a new file is loaded (you can restrict the number of requests form the page by employing logic like request will be sent only after use clicks on the desktop app button on the web page, etc). 您可以使用JavaScript / JQuery / AJax来连续检查服务器上是否已加载新文件(您可以通过采用如下逻辑来限制来自页面的请求数,例如仅在使用用户单击Web上的desktop app按钮后才发送请求页等)。 When a new file is loaded, popup the notification message. 加载新文件后,弹出通知消息。

HTH. HTH。

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

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