Silverlight 4 HttpWebRequest用户代理字符串为空 [英] Silverlight 4 HttpWebRequest user agent string is null

查看:189
本文介绍了Silverlight 4 HttpWebRequest用户代理字符串为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题



我有一个带有silverlight对象的页面。它试图从另一个(外部跨域)页面检索XML。但我正在努力解决安全问题。



这段代码在WPF中表现出色。



使用一个使用相同代码托管Silverlight应用程序的网站,HttpRequest对象的用户代理字符串为空(并且看起来不能设置)。事实上,根本没有标题信息 - 这会在尝试进行异步调用时导致安全异常。



问题



为什么在使用HttpWebRequest进行异步调用时,我的silverlight 4应用程序中的用户代理字符串(和标题信息)为空?

解决方案

听起来像是你可能会碰到跨性别问题
您的外部xml在网站上是否有clientaccesspolicy文件或跨域文件?
http://msdn.microsoft.com /en-us/library/cc197955(VS.95).aspx



还有什么例外?你可以发布。



更新:



代码,是的它是一个交叉问题。该网站 http://eu.wowarmory.com/ 有跨文件文件,但只允许访问该文件中列出的网站?你是网站之一吗?如果没有,您正在实现跨域安全。 (WPF在完整的CLR上运行,因此没有这些限制。)

有选项...
- 在提升的信任下运行的SILVERlight 4是一个 - 但这是OOB



- 在Javascript中执行此操作并将数据传递到Silverlight中



- 让您服务器做你的工作,即代理



- 让他们改变crossdomain文件!



其他人真的取决于你想要达到的目标吗?你能解释一下吗?


The problem

I have a page with a silverlight object. It attempts to retrieve XML from another (external cross domain) page. But I am struggling with a security exception.

I have this code working brilliantly in WPF.

When using a website hosting a silverlight application with the same code, the user agent string of the HttpRequest object is null (and seemingly cannot be set). In fact there is no header information at all - this causes a security exception when attempting to make my asynchronous call.

The question

Why is the user-agent string (and header information) null in my silverlight 4 application when making an asynchronous call using HttpWebRequest?

Thanks in advance!

解决方案

sounds like you are might be hitting a cross domian issue does your external xml have a clientaccesspolicy file or a crossdomain file on the site? http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx

Also what is the exception ? can you post.

Update:

OK, Have looked and run your code and yes it a crossdomian issue. The site "http://eu.wowarmory.com/" has a crossdomian file but only allow access from the sites listed in that file ? is you site one of those ? If not you are hitting crossdomain security. (WPF runs on the full CLR and so does not have these restrictions.)

There are options ... -Silverlight 4 running in elevated trust is one - but that is OOB

-Doing it in Javascript and the passing the data into Silverlight

-Get you server to do the work for you i.e. proxy

-Get them to change the crossdomain file !

There are others it really depends on what you are trying to achieve overall? can you explain more ?

这篇关于Silverlight 4 HttpWebRequest用户代理字符串为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆