且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何Web App和Windows窗体应用程序之间的交互

更新时间:2023-12-06 14:35:04

你问什么是可能的,但似乎尴尬。

What you're asking for is possible but seems awkward.

试图拨打从网页应用程序是不是你可以出于安全考虑做。但是你可以做这将有一定类型的文件关联的桌面应用程序,然后使用内容类型的网页上,以确保这种类型的URL打开时,您的应用程序被调用。这将是类似于MS Office处理的.doc或.xls文件或媒体播放器打开名为.mp3或.wmv文件的方式。

Trying to call an application from a web page is not something you could do due to security considerations. You could however make a desktop application which would be associated with a certain type of files and then use content-type on the web page to make sure that your app is called when a URL with this type is opened. It would be similar to the way MS Office handles .doc or .xls documents or the Media Player opens the .mp3 or .wmv files.

第二部分(从你的应用程序中打开特定网页)更容易。
正如你应该知道你的网页的地址来创建一个URL字符串与你想要的参数,并在默认浏览器中打开它(有大量的例子就如何做到这一点,一个样本是下文)。

The second part (opening a particular web page from your application) is easier. As you should know the address of your web page create a URL string with the parameters you want and open it in default browser (there are plenty of examples on how to do that, a sample is below).

System.Diagnostics.Process.Start("http://example.com?key=value");

如果您想更新已经打开浏览器页面或使用您选择的浏览器(即始终IE6,而不是歌剧或Chrome),那么你就必须做一些功课,但它仍然是相当容易的。

If you want to update the page in the already opened browser or use a browser of your choice (i.e. always IE6 instead of Opera or Chrome) then you'll have to do some homework but it's still quite easy.