.Net 桌面应用程序和 ASP.NET Web 应用程序之间的通信
场景 1:工作
在 Windows 桌面应用程序中,我打开一个浏览器窗口(在 ShDocVw.InternetExplorer 的帮助下),加载托管站点的页面并将属性设置为某个值(例如,lblName) .Text =“史蒂夫·M”)。现在,使用 ShDocVw.InternetExplorer,我可以检查是否存在具有指定名称的浏览器对象。通过这样做,我将防止打开重复的浏览器窗口。
场景 2:问题
现在,我想要执行以下操作。 我将通过在 Internet Explorer 的地址栏中键入地址来打开上一页。因此它将加载相同的名称(例如,lblName.Text =“Steve M.”)。 如果我打开桌面应用程序并重复场景 1,则会打开一个重复的窗口。
我怎样才能防止这个问题?
我尝试将桌面应用程序的引用添加到 Web 应用程序。但没有任何效果:(
Scenario 1:Working
From a Windows Desktop Application, I open a browser window (with the help of ShDocVw.InternetExplorer), load a page of a hosted site and sets a property to some value( say, lblName.Text = "Steve M."). Now, using the ShDocVw.InternetExplorer, I can check if a browser object exist with a specified name. By doing so, I will prevent to open duplicate browser window.
Scenario 2:Issue
Now, I want to do the following.
I will open the previous page by typing the address in Internet Explorer's address bar. So it will load with the same name( say, lblName.Text = "Steve M.").
If I open the Desktop Application and repeat the Scenario 1 a duplicate window will be opened.
How can I prevent the issue ?
I tried with adding reference of Desktop Application to Web application. But nothing worked :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否控制该 asp.net 站点(您可以更改其代码)吗?
我对桌面应用程序了解不够,无法告诉您这是否可能;对我来说这似乎不可能或非常困难;毕竟,浏览器的私有到打开的网页业务是由 JS 对象为其运行的[页面]。
但是,也许您可以这样做:在 JS 对象初始化时,使用 JS 代码将页面标题更改为固定的内容,这对您的桌面应用程序来说意味着您正在查找的对象已准备就绪。
例如,通常,当页面加载时,页面标题是“我的特殊页面”。也许在加载对象后,您可以将标题更改为“我的特殊页面就绪”(或者如果您关心的话,不会让用户看起来很奇怪)。
然后,您可以在桌面应用程序中进行进程搜索,查找“我的特殊页面就绪”浏览器窗口,如果没有找到,则启动浏览器;否则你就不会。与研究如何要求 IE(或您正在使用的其他浏览器)告诉您其打开的选项卡中的某个变量是否存在并具有值(同样,如果可能的话)相比,这是相当简单的。
Do you control that asp.net site (can you change its code)?
I don't know enough about desktop apps to tell you if that's even possible; it seems impossible or very difficult to me; after all, it's the browser's private-to-opened-webpage business what JS objects it's got running for it [the page].
However, maybe you can do this: as that JS object initializes, use JS code to change the page title to something fixed that will mean to your desktop app that that object you're looking for has been made ready.
E.g, normally, the page title is "My Special Page" when that page loads. Maybe after the object is loaded, you can change the title to "My Special Page Ready" (or something that won't make it look weird to the user, if you even care).
Then, you can look for "My Special Page Ready" browser windows, from within the desktop app doing the process search, and if you don't find one, you launch the browser; otherwise you don't. It's fairly simple, compared to researching how to ask IE (or other browser you're working in) to tell you if some variable within its opened tabs exists and has a value (again, if that's even possible).