简体   繁体   English

C# WPF,以及与浏览器的数据交换

[英]C# WPF, and data exchange with the browser

I've a C# WPF application developed in VS 2015, and I want the browser to read some data from it.我有一个在 VS 2015 中开发的 C# WPF 应用程序,我希望浏览器从中读取一些数据。 Just a short string.只是一个短字符串。 I can save it in a text file, or in a variable but it should be visible to the browser (using JS I suppose).我可以将它保存在文本文件或变量中,但它应该对浏览器可见(我想是使用 JS)。 For instance using file:/// doesn't work if the original page is hosted online - as in my case (different source conflict).例如,如果原始页面是在线托管的,则使用 file:/// 不起作用 - 就像我的情况一样(不同的源冲突)。 This should work in Opera and FFox, but looking at their extensions, it seems you can only develop with front-end technologies, which are not enough in my case since I use WPF to look into Win OS, and then I need to share the result with the browser.这应该适用于 Opera 和 FFox,但是查看它们的扩展,您似乎只能使用前端技术进行开发,这在我的情况下还不够,因为我使用 WPF 来查看 Win OS,然后我需要分享结果与浏览器。

I suspect it's possible, and no , it's not to write a malicious piece of code.我怀疑这是可能的,不,这不是编写恶意代码。 For instance I can read the details of the graphic card for diagnostic purposes.例如,我可以读取图形卡的详细信息以进行诊断。 Please help, many thanks.请帮忙,非常感谢。

Browsers run in a security sandbox which is intended to stop them reading or writing files to the file system.浏览器在安全沙箱中运行,该沙箱旨在阻止浏览器向文件系统读取或写入文件。 You could write to the user's appdata.您可以写入用户的应用程序数据。 There are various javascript frameworks which persist data to there so they can provide offline or static data.有各种 javascript 框架可以将数据持久化到那里,以便它们可以提供离线或静态数据。 I don't think that is a good plan though.不过我认为这不是一个好的计划。

I suggest your first candidate would be a cookie.我建议你的第一个候选人是饼干。 Quick google on how to do that, I find: How to create cookie in c#.net windows application?快速谷歌如何做到这一点,我发现: How to create cookie in c#.net windows application?

From a web page you can use the content of a cookie dynamically.您可以从网页动态使用 cookie 的内容。 So you could change what you see in the web page after it's up and running from some process in your wpf app and do a counter or whatever.因此,在您的 wpf 应用程序中的某个进程启动并运行后,您可以更改您在网页中看到的内容,并执行计数器或其他操作。

I've not used this with windows apps and a browser but I have with a web app and Silverlight.我没有在 Windows 应用程序和浏览器中使用它,但我在网络应用程序和 Silverlight 中使用过它。 I'm afraid I don't have that code to hand though.恐怕我手头没有那个代码。

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

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