Silerlight 安全性错误

cctsong 2012-06-18 05:51:56

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 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
...全文
316 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Blessed_Chuan 2012-07-05
  • 打赏
  • 举报
回复
请问解决了吗?
我也遇到了


private void Button_Click(object sender, RoutedEventArgs e)
{
string topic = SearchTxt.Text;

string diggurl = string.Format("http://services.digg.com/stories/topic/{0}?count=20&appkey=http%3A%2F%2Fscottgu.com",topic);
//string diggurl = "http://services.digg.com/stories";
WebClient diggservice = new WebClient();
diggservice.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DiggService_DownloadStoriesCompleted);
diggservice.DownloadStringAsync(new Uri(diggurl));
}
void DiggService_DownloadStoriesCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
string result = e.Result;
DisplayStories(result);

//可以在这里写解析xml
}
}
cctsong 2012-06-19
  • 打赏
  • 举报
回复
手误,将 localhost给拼错了
jv9 2012-06-19
  • 打赏
  • 举报
回复
“但在abc 的e.Error中不能获取返回值。”这句什么意思?是使用了其他域名么? 你使用自定义端口,能确认这个端口在目标服务器是正常的么?
sundayX 2012-06-19
  • 打赏
  • 举报
回复
1、hocalhost是什么东西?localhost?
2、e.Error中是错误信息,怎么会获得返回值?
3、既然e.Error==null了,你再取e.Error.Message能取出来么?
4、这种问题一般是策略文件导致,无法找到策略文件引起。silverlight5可以提升浏览器权限来消去该问题,silverlight4及以下需要在服务端添加策略文件。

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧