所以你可以只使用WebClient 类并获取页面。
(我假设你在做 asp.net WebForms 而不是 MVC)
您的 asp.net 页面应该是一个空白页面,在您后面的代码中读取您的查询字符串并使用它执行您需要的操作,这取决于您使用 Response.Write(); 编写适当的响应的成功或失败。
在您的 silverlight 代码中,您只需要请求您的页面,然后您就可以从您的 asp.net 页面读取响应。
Asp.net:
var encyString = Request.QueryString["str"];
//some logic
Response.Write("Success");
银光:
WebClient client = new WebClient();
client.DownloadStringCompleted +=
new DownloadStringCompletedEventHandler(
client_DownloadStringCompleted);
在Button1_Click 中,我调用DownloadStringAsync,传递包含用户指定号码的完整URL。
private void Button1_Click(object sender, RoutedEventArgs e)
{
string encryptedString = "example";
client.DownloadStringAsync
(new Uri("http://testsite.com/mypage.aspx?"+encryptedString));
}
在 DownloadStringCompleted 事件处理程序中,我检查事件 args 的 Error 属性是否为空,然后将响应或错误消息输出到文本块。
void client_DownloadStringCompleted(object sender,
DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
resultBlock.Text = "Using WebClient: "+ e.Result;
//will be Response.Write();
else
resultBlock.Text = e.Error.Message;
}
以上代码抄袭自this blog。
请记住,嗅探器可以读取您的请求。如果您需要更好的安全性,您可能需要使用 SSL。发送此数据的一种更安全的方法可能是将其发布到您的 asp.net 页面。
This article 描述了如何从 silverlight POST 到页面。
HTH