【问题标题】:Create new instance of a page and obtain URL创建页面的新实例并获取 URL
【发布时间】:2010-08-06 09:37:41
【问题描述】:

我是一名初学者网络程序员。我主要编写桌面应用程序。 现在,我在 Silverlight 中创建了这个 Web 应用程序,它使用我自己的 Web 服务来查询数据库。问题是,应用程序功能之一是能够打开 PDF 文件。我知道silverlight 不会让您这样做,但是在silverlight 应用程序之上使用IFrame,您可以显示带有de pdf 文件的页面(使用acrobat 插件)。 所以问题来了,我的 silverlight 应用程序将 pdf 路径传递给 Web 服务,作为回报,Web 服务将创建一个新页面并将新页面 URI 传回,以便它可以显示在 IFrame 上:

页面代码行为:

public partial class PDFViewer : System.Web.UI.Page
{
    string Filename = string.Empty;

    public Uri Uri
    {
        get { return HttpContext.Current.Request.Url; }
    }

    public PDFViewer(string filename)
    {
        Filename = filename;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "Application/pdf";

        Response.WriteFile(Filename); //Write the file directly to the HTTP content output stream.

        Response.End();
    }
}

WebMethod 代码:

    [WebMethod]
    public string GetReport(string filename)
    {
        PDFViewer viewer = new PDFViewer(filename);

        return viewer.Uri.AbsoluteUri;
    }

这仅返回 Web 服务 URL。 所以主要的问题是:如何创建一个页面实例并获取该页面的URL?

解决方案可能在这里: http://forums.silverlight.net/forums/p/76977/372282.aspx

“在我的 Silverlight 应用程序中,我通过传入查询字符串我的 id 和页面处理它来打开一个新的 Web 浏览器,查询数据库,检索所选对象并使用响应方法呈现。”

我只是不知道该怎么做。

非常感谢任何帮助。

佩德罗

【问题讨论】:

    标签: c# asp.net silverlight web-services


    【解决方案1】:

    也许这会有所帮助。

    无论您的 silverlight 对象被嵌入到哪里,放置一个 id="xContainer" 的 iframe

    然后从您的 silverlight 代码中将其 scr 设置为您要显示的 pdf

    HtmlPage.Document.GetElementById("xContainer").SetProperty("src", "http://google.com");
    

    【讨论】:

    • 感谢您的回答,但我认为这并不能解决我的问题。 pdf 文件本地存储在服务器中,但未与应用程序一起部署。由于 Web 服务位于服务器计算机中,因此它可以访问给定目录中的文件(例如 c:\\test.pdf)。这就是我创建 PDFViewer 页面并将其传递给 pdf 路径的原因。现在如何访问页面 URL,以便我的 silverlight 客户端将其加载到 iframe 中?提前致谢
    猜你喜欢
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多