Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8069407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:00:34+00:00 2026-06-05T13:00:34+00:00

I’m in an Asp.Net MVC web application. For a specific action, I’ve to return

  • 0

I’m in an Asp.Net MVC web application.

For a specific action, I’ve to return a file generated from another internal server. This server require some credentials that web users doesn’t own. So the Asp.net MVC server must connect itself to this server, download and send the downloaded file to the client.

Actually I’m doing it through an ActionResult:

public class ReportServerFileResult : FileResult
    {
        private readonly string _host;
        private readonly string _domain;
        private readonly string _userName;
        private readonly string _password;
        private readonly string _reportPath;
        private readonly Dictionary<string, string> _parameters;

        /// <summary>
        /// Initializes a new instance of the <see cref="ReportServerFileResult"/> class.
        /// </summary>
        /// <param name="contentType">Type of the content.</param>
        /// <param name="host">The host.</param>
        /// <param name="domain">The domain.</param>
        /// <param name="userName">Name of the user.</param>
        /// <param name="password">The password.</param>
        /// <param name="reportPath">The report path.</param>
        /// <param name="parameters">The parameters.</param>
        public ReportServerFileResult(string contentType, String host, String domain, String userName, String password, String reportPath, Dictionary<String, String> parameters)
            : base(contentType)
        {
            _host = host;
            _domain = domain;
            _userName = userName;
            _password = password;
            _reportPath = reportPath;
            _parameters = parameters;
        }

        #region Overrides of FileResult

        /// <summary>
        /// Writes the file to the response.
        /// </summary>
        /// <param name="response">The response.</param>
        protected override void WriteFile(HttpResponseBase response)
        {
            string reportUrl = String.Format("http://{0}{1}&rs:Command=Render&rs:Format=PDF&rc:Toolbar=False{2}",
                                             _host,
                                             _reportPath,
                                             String.Join("", _parameters.Select(p => "&" + p.Key + "=" + p.Value)));


            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(reportUrl);
            request.PreAuthenticate = true;
            request.Credentials = new NetworkCredential(_userName, _password, _domain);
            HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();
            Stream fStream = webResponse.GetResponseStream();
            webResponse.Close();

            fStream.CopyTo(response.OutputStream);
            fStream.Close();
        }

        #endregion
    }

But I don’t like how stream are managed, because(if I’ve good correctly understood), we retrieve the full stream of the file and then starting to send it to the final user.

But it means that we are going to load the full file in memory, no?

So I was wondering if it is possible to give to the HttpWebRequest the stream in which it has to write the response? To stream directly the web response to the output?

Is it possible? Do you have another idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:00:35+00:00Added an answer on June 5, 2026 at 1:00 pm

    You are already connecting the two streams. Just because you call GetResponse() will not read the entire data to memory.

    The CopyTo() should read data from the source stream as needed, when the target stream can accept writing, depending on the transmission speed of the target stream.

    Do you have any metrics that indicate that the entire content gets read into the memory of the web process?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.