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

  • SEARCH
  • Home
  • 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 6119139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:31:02+00:00 2026-05-23T15:31:02+00:00

I have implemented something similar to this only real difference is string filename =

  • 0

I have implemented something similar to this
only real difference is

string filename = context.Request.RawUrl.Replace("/", "\\").Remove(0,1);
string path = Uri.UnescapeDataString(Path.Combine(_baseFolder, filename));

so that I can traverse to subdirectories. This works great for webpages and other text file types but when trying to serve up media content I get the exception

HttpListenerException: The I/O
operation has been aborted because of
either a thread exit or an application
request

Followed by

InvalidOperationException: Cannot close stream until all bytes are written.

In the using statement.

Any suggestions on how to handle this or stop these exceptions?

Thanks

  • 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-05-23T15:31:03+00:00Added an answer on May 23, 2026 at 3:31 pm

    I should mention that I am using Google Chrome for my browser (Google Chrome doesn’t seem to care about the MIME types, when it sees audio it will try to use it like it’s in a HTML5 player), but this is also applicable if you are trying to host media content in a page.

    Anyways, I was inspecting my headers with fiddler and noticed that Chrome passes 3 requests to the server. I started playing with other browsers and noticed they did not do this, but depending on the browser and what I had hard coded as the MIME type I would either get a page of crazy text, or a download of the file.

    On further inspection I noticed that chrome would first request the file. Then request the file again with a few different headers most notably the range header. The first one with byte=0- then the next with a different size depending on how large the file was (more than 3 requests can be made depending how large the file is).

    So there was the problem. Chrome will first ask for the file. Once seeing the type it would send another request which seems to me looking for how large the file is (byte=0-) then another one asking for the second half of the file or something similar to allow for a sort of streaming experienced when using HTML5. I coded something quickly up to handle MIME types and threw a HTML5 page together with the audio component and found that other browsers also do this (except IE)

    So here is a quick solution and I no longer get these errors

    string range = context.Request.Headers["Range"];
    int rangeBegin = 0;
    int rangeEnd = msg.Length;
    if (range != null)
    {
        string[] byteRange = range.Replace("bytes=", "").Split('-');
        Int32.TryParse(byteRange[0], out rangeBegin);
        if (byteRange.Length > 1 && !string.IsNullOrEmpty(byteRange[1]))
        {
           Int32.TryParse(byteRange[1], out rangeEnd);
        }
    }
    
    context.Response.ContentLength64 = rangeEnd - rangeBegin;
    using (Stream s = context.Response.OutputStream)
    {
        s.Write(msg, rangeBegin, rangeEnd - rangeBegin);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering about how you would implement an effect similar to this one implemented
Let's say I have ClasseA implements I , how do I do something like:
I have a class Something that implements ISomething . How can I convert/cast from
I am looking to implement a continuous unit test running system, something I have
I have implemented the A* algorithm in AS3 and it works great except for
I have implemented Facebook Connect into a HTML page exactly as the tutorial explains
I have implemented a VSS requester, and it links compiles and executes on Windows
I have implemented a ToString() override method for my class in my Webservice and
I have implemented a sort of Repository class and it has has GetByID ,
I have implemented a DAL using Rob Conery's spin on the repository pattern (from

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.