需要使用“GetStream”显示 html 页面的方法类型

发布于 2024-10-10 18:18:28 字数 3492 浏览 4 评论 0原文

我有一个用户控件,它当前读取 xml 文件中的数据并将其返回到浏览器。 xml 文件位于不同的服务器上。该代码生成一个动态 url,然后通过 GetStream 方法将 xml 从该 url 返回到浏览器。这按预期工作。我现在需要做的是更进一步...返回的数据显示 html 文件的链接列表。这些链接在公司网络内部工作,就像打开任何 URL 一样...但是,由于防火墙限制,它们在公司网络外部不起作用。但我们显然有能力显示来自该服务器的数据,因为它可以显示来自 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 文件所做的事情并将其传输到浏览器。只是不太确定该怎么做。

任何帮助都会很棒!

I have a usercontrol which currently reads and returns the data from an xml file to the browser. The xml file is located on a different server. The code generates a dynamic url, then returns the xml from that url to the browser via the GetStream method. This works as expected. What I now need to be able to do is take it one step further...the returned data displays a list of links to html files. These links work inside the corporate network just like opening any url...however they don't work from outside the corporate network b/c of firewall restrictions. But we obviously have the ability to display data from that server b/c it can display the data from the xml file...which is in the same location/server as the html files. So, how do I display the html data when a user clicks on one of these links?

Here's what we have so far:

// 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;
    }

// here's the GetStream method

 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;
    }

// here's datasource and gridview code we use to display what we've retrieved from the html

<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>

//and the associated codebehind

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;
    }

Remember this does work inside the network, but from outside the network it doesn't. So I'm thinking there is a way to essentially do what we're doing with the xml file and stream it to the browser. Just not quite sure how to go about that.

Any help would be great!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

止于盛夏 2024-10-17 18:18:28

解决此问题的一种方法是修改页面,以便不再提供文件的链接,而是向 Web 服务器发送请求,其中包含有关要获取哪个文件的信息,然后 Web 服务器获取该文件并将其提供给用户。

显然,如果用户希望访问文档以进行更改,则更改不会保留到网络存储中,因为它更像是下载而不是直接打开文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文