开发者

Need to use "GetStream" type of method to display html pages

开发者 https://www.devze.com 2023-02-02 21:48 出处:网络
I have a usercontrol which currently reads and returns the data from an xml file to the browser.The xml fi开发者_如何学运维le is located on a different server.The code generates a dynamic url, then re

I have a usercontrol which currently reads and returns the data from an xml file to the browser. The xml fi开发者_如何学运维le 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消