0

我有一个用户控件,它当前从 xml 文件读取数据并将其返回到浏览器。xml 文件位于不同的服务器上。该代码生成一个动态 url,然后通过 GetStream 方法将该 url 中的 xml 返回到浏览器。这按预期工作。我现在需要做的是更进一步......返回的数据显示指向 html 文件的链接列表。这些链接在公司网络内工作,就像打开任何 url 一样......但是它们不能在公司网络外部工作,因为防火墙限制。但是我们显然有能力显示来自该服务器的数据 b/c 它可以显示来自 xml 文件的数据......它与 html 文件位于相同的位置/服务器。那么,当用户单击这些链接之一时,如何显示 html 数据?

以下是我们目前所拥有的:

// Returns a dataset from xml with the html files available to a vendor.
private static DataSet GetDocuments(string VendorId)
    {
        DataSet ds = new DataSet("VendorDocuments");

        if (null != VendorId)
        {
            string uri = ILINKURL + "/supplierstaging/" + VendorId + "/listinfo.xml";

            Stream stream = GetStream(uri);

            ds.ReadXml(stream);

            Logger.Write("Requested drawings for vendor '" + VendorId + "' at " + uri + ".", "Machinery", 5, 200, System.Diagnostics.TraceEventType.Information);
        }

        return ds;
    }

// 这里是 GetStream 方法

 public static Stream GetStream(string uri)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        Stream stream = response.GetResponseStream();

        Logger.Write("got response stream from CompressionMachinery.GetStream('" + uri + "')", "Machinery", 4, 202, System.Diagnostics.TraceEventType.Information);

        return stream;
    }

// 这是我们用来显示从 html 中检索到的内容的数据源和 gridview 代码

<asp:ObjectDataSource ID="CADDrawingsDataSource" runat="server" 
SelectMethod="GetFiles" TypeName="DataAccess.CompressionMachinery" 
FilterExpression="file_type = '{0}' OR 'ALL' = '{0}'">
<FilterParameters>
    <asp:ControlParameter ControlID="rblSearchFileType" Name="file_type" 
        PropertyName="SelectedValue" Type="String" />
</FilterParameters>
<SelectParameters>
    <asp:ControlParameter ControlID="txtPartNumber" DefaultValue="" 
        Name="PartNumber" PropertyName="Text" Type="String" />
</SelectParameters>

<asp:GridView ID="gvCADDrawings" runat="server" AllowPaging="True" 
            AllowSorting="True" DataSourceID="CADDrawingsDataSource" 
            EmptyDataText="No drawings found." PageSize="200" 
            AutoGenerateColumns="False" DataKeyNames="file_name">
            <Columns>
                ...                    
                <asp:TemplateField HeaderText="File Name" SortExpression="file_name">
                    <ItemTemplate>
                        <asp:HyperLink ID="hlFileName" runat="server" Text='<%# Eval("file_name") %>' NavigateUrl='<%# GetUrl(Eval("file_name")) %>'></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
                ...
            </Columns>
        </asp:GridView>

//以及相关的代码隐藏

protected string GetUrl(object file_name)
    {
        string url = m_PartNumberUrlPrefix + m_VendorId + "/";
        if (null != file_name)
        {
            string str = (string)file_name;
            string[] stringArray = str.Split('.');
            string partNumber = stringArray[0];
            url += partNumber + m_PartNumberUrlSuffix;
        }
        return url;
    }

请记住,这在网络内部确实有效,但在网络外部则无效。所以我认为有一种方法可以基本上完​​成我们对 xml 文件所做的事情并将其流式传输到浏览器。只是不太确定该怎么做。

任何帮助都会很棒!

4

1 回答 1

1

One solution to this would be to modify the page so that instead of providing the link to the file it sends a request to the web server with the information about what file to get and then the web server fetches the file and serves it up to the user.

Obviously if the user is looking to get access to the document to make changes the changes wouldn't be persisted to the network store as it would act more like a download instead of a direct file open.

于 2011-01-07T19:39:25.063 回答