用silverlight调用aspx页面,但不打开它

本文关键字:silverlight 调用 aspx 页面 | 更新日期: 2023-09-27 18:20:53

在我的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回答后,现在还有另一个问题:

W为什么我不能在那里使用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

用silverlight调用aspx页面,但不打开它

您可以使用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();