Silerlight 安全性错误C# codeprivate void Books_SelectionChanged(object sender, SelectionChangedEven
Silerlight 安全性错误
C# code private void Books_SelectionChanged(object sender, SelectionChangedEventArgs e) { Uri endpoint = new Uri(String.Format("http://hocalhost:26066/BookHandler.ashx?No={0}", Books.SelectedIndex)); WebClient client = new WebClient(); client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(abc); client.DownloadStringAsync(endpoint); } void abc(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { lblPrice.Text = "价格:" + e.Result; lblPrice.Text = e.Error.Message; } }
执行 Books_SelectionChanged 事件,正常能从BookHandler.ashx中获取返回值,但在abc 的e.Error中不能获取返回值。
异常信息:
-e.Error{System.Security.SecurityException ---> System.Security.SecurityException: 安全性错误。
位于 System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
位于 System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
位于 System.Net.Browser.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
--- 内部异常堆栈跟踪的结尾 ---
位于 System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
位于 System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
位于 System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
位于 System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)}System.Exception {System.Security.SecurityException}
Books_SelectionChanged是调用别的项目里面的 BookHandler.ashx的,我也在 BookHandler.ashx的根目录下面加了clientaccesspolicy.xml
XML code<?xml version="1.0" encoding="utf-8"?><access-policy> <cross-domain-access> <policy> <allow-from http-request-headers="*"> <domain uri="*"/> </allow-from> <grant-to> <resource path="/" include-subpaths="true"/> </grant-to> </policy> </cross-domain-access></access-policy>
但是还是一样的错误,本人silverlight新手。。请各位大侠指点下~~ T.T
[解决办法]“但在abc 的e.Error中不能获取返回值。”这句什么意思?是使用了其他域名么? 你使用自定义端口,能确认这个端口在目标服务器是正常的么?
[解决办法]1、hocalhost是什么东西?localhost?
2、e.Error中是错误信息,怎么会获得返回值?
3、既然e.Error==null了,你再取e.Error.Message能取出来么?
4、这种问题一般是策略文件导致,无法找到策略文件引起。silverlight5可以提升浏览器权限来消去该问题,silverlight4及以下需要在服务端添加策略文件。