c# - 在 silverlight 中调用一个 aspx 页面,而不打开它

标签 c# asp.net silverlight system.net.httpwebrequest

在我的 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/

相关文章:

c# - 我如何进行列表遍历?

c# - ServiceStack Client Put请求和查询参数

c# - Visual Studio 2015 Silverlight Ria 服务项目引用

c# - IO异常 : The account used is a computer account

c# - 什么是 C# 等同于 preg_match_all?

asp.net - 结构图 x Asp.net 标识

c# - asp.net中displayfor和displaynamefor的简单解释是什么?

c# - 使用 ConfigurationBuilder 设置基本路径

c# - WPF 控件和边距与窗口大小成比例

silverlight - 确定对象是否可见和可点击