The server committed a protocol violation. Section=ResponseStatusLine

Discussion in 'ASP .Net' started by Alon Albert, Jan 30, 2007.

  1. Alon Albert

    Alon Albert Guest

    I have an ASP.NET that has an aspx that serves a binary file for download. I
    need this rather than a direct link for various reasons.

    I am getting the following error intermitently:

    The server committed a protocol violation. Section=ResponseStatusLine

    I tried adding:
    <system.net>
    <settings>
    <httpWebRequest useUnsafeHeaderParsing="true" />
    </settings>
    </system.net> to the web.config file but made no difference.

    I am using .NET 2.0.
    The download client is also a .NET application.

    The code that serves the file looks like this:

    private void Page_Load(object sender, System.EventArgs e) {
    string filename = Request["filename"];
    string path = string.Format("c:/files/{0}", filename);

    Response.ContentType = "APPLICATION/octet-stream";
    Response.AddHeader("Content-Disposition",
    string.Format("attachment;filename={0}", filename));
    FileInfo fi = new FileInfo(path);
    Response.AddHeader("Content-Length", fi.Length.ToString());
    Response.Flush();
    Response.TransmitFile(path);
    Response.End();
    }

    The client code reads from
    WebRequest.Create(url).GetResponse().GetResponseStream().

    Any ideas? I have run out of my own.
    Alon Albert, Jan 30, 2007
    #1
    1. Advertising

  2. RE: The server committed a protocol violation. Section=ResponseStatusL

    I think the problem may be the "attachment;" header. If you are using
    WebRequest, what you really want to do is just stream out the data, not as an
    "attachment".
    Peter

    --
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    Short urls & more: http://ittyurl.net




    "Alon Albert" wrote:

    > I have an ASP.NET that has an aspx that serves a binary file for download. I
    > need this rather than a direct link for various reasons.
    >
    > I am getting the following error intermitently:
    >
    > The server committed a protocol violation. Section=ResponseStatusLine
    >
    > I tried adding:
    > <system.net>
    > <settings>
    > <httpWebRequest useUnsafeHeaderParsing="true" />
    > </settings>
    > </system.net> to the web.config file but made no difference.
    >
    > I am using .NET 2.0.
    > The download client is also a .NET application.
    >
    > The code that serves the file looks like this:
    >
    > private void Page_Load(object sender, System.EventArgs e) {
    > string filename = Request["filename"];
    > string path = string.Format("c:/files/{0}", filename);
    >
    > Response.ContentType = "APPLICATION/octet-stream";
    > Response.AddHeader("Content-Disposition",
    > string.Format("attachment;filename={0}", filename));
    > FileInfo fi = new FileInfo(path);
    > Response.AddHeader("Content-Length", fi.Length.ToString());
    > Response.Flush();
    > Response.TransmitFile(path);
    > Response.End();
    > }
    >
    > The client code reads from
    > WebRequest.Create(url).GetResponse().GetResponseStream().
    >
    > Any ideas? I have run out of my own.
    >
    >
    >
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Jan 30, 2007
    #2
    1. Advertising

  3. Alon Albert

    Alon Albert Guest

    Re: The server committed a protocol violation. Section=ResponseStatusL

    I'll give it a try. I think the reason I put that in was so that if I
    download from a browser, it will prompt the proper filename rather than the
    aspx page name. I think I found this in a an example somewhere. Is there
    another way to do this? have the filename be prompted properly I mean?

    Also, any idea why this would be happening intermittently?

    "Peter Bromberg [C# MVP]" <> wrote in
    message news:...
    >I think the problem may be the "attachment;" header. If you are using
    > WebRequest, what you really want to do is just stream out the data, not as
    > an
    > "attachment".
    > Peter
    >
    > --
    > Site: http://www.eggheadcafe.com
    > UnBlog: http://petesbloggerama.blogspot.com
    > Short urls & more: http://ittyurl.net
    >
    >
    >
    >
    > "Alon Albert" wrote:
    >
    >> I have an ASP.NET that has an aspx that serves a binary file for
    >> download. I
    >> need this rather than a direct link for various reasons.
    >>
    >> I am getting the following error intermitently:
    >>
    >> The server committed a protocol violation. Section=ResponseStatusLine
    >>
    >> I tried adding:
    >> <system.net>
    >> <settings>
    >> <httpWebRequest useUnsafeHeaderParsing="true" />
    >> </settings>
    >> </system.net> to the web.config file but made no difference.
    >>
    >> I am using .NET 2.0.
    >> The download client is also a .NET application.
    >>
    >> The code that serves the file looks like this:
    >>
    >> private void Page_Load(object sender, System.EventArgs e) {
    >> string filename = Request["filename"];
    >> string path = string.Format("c:/files/{0}", filename);
    >>
    >> Response.ContentType = "APPLICATION/octet-stream";
    >> Response.AddHeader("Content-Disposition",
    >> string.Format("attachment;filename={0}", filename));
    >> FileInfo fi = new FileInfo(path);
    >> Response.AddHeader("Content-Length", fi.Length.ToString());
    >> Response.Flush();
    >> Response.TransmitFile(path);
    >> Response.End();
    >> }
    >>
    >> The client code reads from
    >> WebRequest.Create(url).GetResponse().GetResponseStream().
    >>
    >> Any ideas? I have run out of my own.
    >>
    >>
    >>
    Alon Albert, Jan 30, 2007
    #3
  4. Alon Albert

    Alon Albert Guest

    RE: The server committed a protocol violation. Section=ResponseStatusL

    In article <>,
    says...
    > I think the problem may be the "attachment;" header. If you are using
    > WebRequest, what you really want to do is just stream out the data, not as an
    > "attachment".


    Well, I removed the attachment code but it still happens. Any other
    ideas?
    Alon Albert, Feb 3, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U3RldmVu?=

    Committed Memory issue

    =?Utf-8?B?U3RldmVu?=, Feb 2, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    3,218
    =?Utf-8?B?U3RldmVu?=
    Feb 2, 2005
  2. =?Utf-8?B?U2NvdHQgTWNEZXJtb3R0?=

    Why do I get "The server committed a protocol violation"?

    =?Utf-8?B?U2NvdHQgTWNEZXJtb3R0?=, Jul 18, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    84,023
  3. Replies:
    0
    Views:
    4,256
  4. FabMahesh
    Replies:
    0
    Views:
    524
    FabMahesh
    Dec 11, 2007
  5. sduncansca

    The server committed an HTTP protocol violation

    sduncansca, Oct 9, 2005, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    365
Loading...

Share This Page