在我的 silverlight 应用程序中,我调用了一个 aspx 页面,以在目录中创建和注册一个 txt 文件。
Uri ub = (new Uri(HtmlPage.Document.DocumentUri, "GenereInfos.aspx?&connexion=" + connexion + ";&id=" + this.Id));
if (HtmlPage.IsPopupWindowAllowed)
{
HtmlPopupWindowOptions opt = new HtmlPopupWindowOptions();
HtmlPage.PopupWindow(ub, "file", opt);
}
else
{
HtmlPage.Window.Navigate(ub);
}
我必须通过我的 aspx 页面来生成我的 txt 文件,因为 silverlight 不允许这样做。
这里的问题是,会出现弹窗,或者页面会加载新的uri。
我想要的是仅调用 asp 中的代码(完美运行),而不加载 uri。
有办法吗?
编辑: DGibbs 回答后,现在有另一个问题:
我不能在那里使用 GetResponse() 吗?
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(new Uri
(HtmlPage.Document.DocumentUri, "GenereInfos.aspx?&connexion=" + connexion + ";&idPocedure=" + itmProcedure.IdProcedure));
string response = new System.IO.StreamReader(req.GetResponse().GetResponseStream()).ReadToEnd();
这里有一点回答:Silverlight 是异步的,所以,我们不能调用同步的 GetResponse。
因此,调用我的 aspx 页面的最佳方式是使用 WebClient found here
最佳答案
你可以只使用 WebRequest :
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri
(HtmlPage.Document.DocumentUri, "GenereInfos.aspx?&connexion=" + connexion + ";&id=" + this.Id));
string response = new System.IO.StreamReader(req.GetResponse()
.GetResponseStream()).ReadToEnd();
关于c# - 在 silverlight 中调用一个 aspx 页面,而不打开它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17428546/