Help with streaming binary content to Safari

Discussion in 'ASP .Net' started by Brad, Jun 3, 2008.

  1. Brad

    Brad Guest

    I have an aspx page that is sending pdf files to client browsers: it uses a filestream to read the pdf file and
    response.binarywrite to send content to the browser. This has worked great for years in IE, Firefox and Opera on
    windows, and it works on a Mac with Firefox and Opera. But this fails in Safari with the generic message "A network
    error occurred while accessing this document".

    Here is a link to try out http://www.lanecounty.org/TaxMap/ViewFile.aspx?type=TM&id=2380


    Here is a code snippet for the page.

    switch (fi.Extension.ToLower())
    {
    case ".tif":
    case ".tiff":
    contentType = "image/tiff";
    break;
    case ".pdf":
    contentType = "application/pdf";
    break;
    }

    //########################################
    FileStream fs = new FileStream(imageFile, FileMode.Open);
    try
    {
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.Buffer = true;
    HttpContext.Current.Response.ContentType = contentType;

    int FileLength = System.Convert.ToInt32(fs.Length);
    byte[] buffer = new byte[FileLength + 1];
    fs.Read(buffer, 0, FileLength);
    HttpContext.Current.Response.BinaryWrite(buffer);

    }
    catch (Exception ex)
    {
    }
    finally
    {
    fs.Close();
    }
    //########################################
    HttpContext.Current.Response.Flush();

    HttpContext.Current.Response.End();
     
    Brad, Jun 3, 2008
    #1
    1. Advertising

  2. Hi Brad,

    From your description, you're using an ASP.NET web page to stream out some
    binary files. And you found that the streaming page work will for IE and
    firefox, but failed with some error when be visited by Safari browser,
    correct?

    From the code snippet you provided, the streaming code look correct. Also,
    I've performed some tests on the public page you provided. I've tried all
    the following browsers on windows system:

    ** IE7
    **FireFox 2.0
    **Safari 3.1.1

    All the test works correctly(display the PDF file in browser). therefore,
    I think the problem should be something specific to the client-side machine
    or the network enviornmente. Have you tried accessing from multiple client
    machine to see the behavior?

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.


    --------------------
    >Reply-To: "Brad" <>
    >From: "Brad" <>
    >Subject: Help with streaming binary content to Safari
    >Date: Mon, 2 Jun 2008 17:47:37 -0700


    >
    >I have an aspx page that is sending pdf files to client browsers: it uses

    a filestream to read the pdf file and
    >response.binarywrite to send content to the browser. This has worked

    great for years in IE, Firefox and Opera on
    >windows, and it works on a Mac with Firefox and Opera. But this fails in

    Safari with the generic message "A network
    >error occurred while accessing this document".
    >
    >Here is a link to try out

    http://www.lanecounty.org/TaxMap/ViewFile.aspx?type=TM&id=2380
    >
    >
    >Here is a code snippet for the page.
    >
    > switch (fi.Extension.ToLower())
    > {
    > case ".tif":
    > case ".tiff":
    > contentType = "image/tiff";
    > break;
    > case ".pdf":
    > contentType = "application/pdf";
    > break;
    > }
    >
    > //########################################
    > FileStream fs = new FileStream(imageFile, FileMode.Open);
    > try
    > {
    > HttpContext.Current.Response.Clear();
    > HttpContext.Current.Response.Buffer = true;
    > HttpContext.Current.Response.ContentType = contentType;
    >
    > int FileLength = System.Convert.ToInt32(fs.Length);
    > byte[] buffer = new byte[FileLength + 1];
    > fs.Read(buffer, 0, FileLength);
    > HttpContext.Current.Response.BinaryWrite(buffer);
    >
    > }
    > catch (Exception ex)
    > {
    > }
    > finally
    > {
    > fs.Close();
    > }
    > //########################################
    > HttpContext.Current.Response.Flush();
    >
    > HttpContext.Current.Response.End();
    >
    >
    >
     
    Steven Cheng [MSFT], Jun 3, 2008
    #2
    1. Advertising

  3. Hi Brad,

    Have you got any progress on this issue? Have you further verify whether
    the problem is specific to the parituclar client machine? If there is
    anything else we can help, welcome to post here.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------
    >From: (Steven Cheng [MSFT])
    >Organization: Microsoft
    >Date: Tue, 03 Jun 2008 05:33:57 GMT
    >Subject: RE: Help with streaming binary content to Safari


    >Hi Brad,
    >
    >From your description, you're using an ASP.NET web page to stream out some
    >binary files. And you found that the streaming page work will for IE and
    >firefox, but failed with some error when be visited by Safari browser,
    >correct?
    >
    >From the code snippet you provided, the streaming code look correct. Also,
    >I've performed some tests on the public page you provided. I've tried all
    >the following browsers on windows system:
    >
    >** IE7
    >**FireFox 2.0
    >**Safari 3.1.1
    >
    >All the test works correctly(display the PDF file in browser). therefore,
    >I think the problem should be something specific to the client-side

    machine
    >or the network enviornmente. Have you tried accessing from multiple client
    >machine to see the behavior?
    >
    >Sincerely,
    >
    >Steven Cheng
    >
    >Microsoft MSDN Online Support Lead
    >
    >
    >Delighting our customers is our #1 priority. We welcome your comments and
    >suggestions about how we can improve the support we provide to you. Please
    >feel free to let my manager know what you think of the level of service
    >provided. You can send feedback directly to my manager at:
    >.
    >
    >==================================================
    >Get notification to my posts through email? Please refer to
    >http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#noti

    f
    >ications.
    >
    >Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    >where an initial response from the community or a Microsoft Support
    >Engineer within 1 business day is acceptable. Please note that each follow
    >up response may take approximately 2 business days as the support
    >professional working with you may need further investigation to reach the
    >most efficient resolution. The offering is not appropriate for situations
    >that require urgent, real-time or phone-based interactions or complex
    >project analysis and dump analysis issues. Issues of this nature are best
    >handled working with a dedicated Microsoft Support Engineer by contacting
    >Microsoft Customer Support Services (CSS) at
    >http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >==================================================
    >This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
    >--------------------
    >>Reply-To: "Brad" <>
    >>From: "Brad" <>
    >>Subject: Help with streaming binary content to Safari
    >>Date: Mon, 2 Jun 2008 17:47:37 -0700

    >
    >>
    >>I have an aspx page that is sending pdf files to client browsers: it

    uses
    >a filestream to read the pdf file and
    >>response.binarywrite to send content to the browser. This has worked

    >great for years in IE, Firefox and Opera on
    >>windows, and it works on a Mac with Firefox and Opera. But this fails

    in
    >Safari with the generic message "A network
    >>error occurred while accessing this document".
    >>
    >>Here is a link to try out

    >http://www.lanecounty.org/TaxMap/ViewFile.aspx?type=TM&id=2380
    >>
    >>
    >>Here is a code snippet for the page.
    >>
    >> switch (fi.Extension.ToLower())
    >> {
    >> case ".tif":
    >> case ".tiff":
    >> contentType = "image/tiff";
    >> break;
    >> case ".pdf":
    >> contentType = "application/pdf";
    >> break;
    >> }
    >>
    >> //########################################
    >> FileStream fs = new FileStream(imageFile, FileMode.Open);
    >> try
    >> {
    >> HttpContext.Current.Response.Clear();
    >> HttpContext.Current.Response.Buffer = true;
    >> HttpContext.Current.Response.ContentType = contentType;
    >>
    >> int FileLength = System.Convert.ToInt32(fs.Length);
    >> byte[] buffer = new byte[FileLength + 1];
    >> fs.Read(buffer, 0, FileLength);
    >> HttpContext.Current.Response.BinaryWrite(buffer);
    >>
    >> }
    >> catch (Exception ex)
    >> {
    >> }
    >> finally
    >> {
    >> fs.Close();
    >> }
    >> //########################################
    >> HttpContext.Current.Response.Flush();
    >>
    >> HttpContext.Current.Response.End();
    >>
    >>
    >>

    >
    >
     
    Steven Cheng [MSFT], Jun 5, 2008
    #3
  4. Brad

    Brad Guest

    I updated Adobe on the Mac and still the same problem. But I found the public site code was actually different from the
    snippet I included in the original post. I updated a test site with code to match my post and it worked so I have
    since updated the public site with that code as it work with the Mac: the difference was the old code just did a
    response.close at the end and the new code does the response.flush and response.end.
    But if I understood you tested the link I provided with Safari and it worked for you (same version of Safari as I have)
    before I did these updates. I would have expected that it would not have worked for you until these updates.


    Brad



    "Steven Cheng [MSFT]" <> wrote in message news:...
    > Hi Brad,
    >
    > Have you got any progress on this issue? Have you further verify whether
    > the problem is specific to the parituclar client machine? If there is
    > anything else we can help, welcome to post here.
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    > Delighting our customers is our #1 priority. We welcome your comments and
    > suggestions about how we can improve the support we provide to you. Please
    > feel free to let my manager know what you think of the level of service
    > provided. You can send feedback directly to my manager at:
    > .
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications.
    > ==================================================
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    > --------------------
    >>From: (Steven Cheng [MSFT])
    >>Organization: Microsoft
    >>Date: Tue, 03 Jun 2008 05:33:57 GMT
    >>Subject: RE: Help with streaming binary content to Safari

    >
    >>Hi Brad,
    >>
    >>From your description, you're using an ASP.NET web page to stream out some
    >>binary files. And you found that the streaming page work will for IE and
    >>firefox, but failed with some error when be visited by Safari browser,
    >>correct?
    >>
    >>From the code snippet you provided, the streaming code look correct. Also,
    >>I've performed some tests on the public page you provided. I've tried all
    >>the following browsers on windows system:
    >>
    >>** IE7
    >>**FireFox 2.0
    >>**Safari 3.1.1
    >>
    >>All the test works correctly(display the PDF file in browser). therefore,
    >>I think the problem should be something specific to the client-side

    > machine
    >>or the network enviornmente. Have you tried accessing from multiple client
    >>machine to see the behavior?
    >>
    >>Sincerely,
    >>
    >>Steven Cheng
    >>
    >>Microsoft MSDN Online Support Lead
    >>
    >>
    >>Delighting our customers is our #1 priority. We welcome your comments and
    >>suggestions about how we can improve the support we provide to you. Please
    >>feel free to let my manager know what you think of the level of service
    >>provided. You can send feedback directly to my manager at:
    >>.
    >>
    >>==================================================
    >>Get notification to my posts through email? Please refer to
    >>http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#noti

    > f
    >>ications.
    >>
    >>Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    >>where an initial response from the community or a Microsoft Support
    >>Engineer within 1 business day is acceptable. Please note that each follow
    >>up response may take approximately 2 business days as the support
    >>professional working with you may need further investigation to reach the
    >>most efficient resolution. The offering is not appropriate for situations
    >>that require urgent, real-time or phone-based interactions or complex
    >>project analysis and dump analysis issues. Issues of this nature are best
    >>handled working with a dedicated Microsoft Support Engineer by contacting
    >>Microsoft Customer Support Services (CSS) at
    >>http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >>==================================================
    >>This posting is provided "AS IS" with no warranties, and confers no rights.
    >>
    >>
    >>--------------------
    >>>Reply-To: "Brad" <>
    >>>From: "Brad" <>
    >>>Subject: Help with streaming binary content to Safari
    >>>Date: Mon, 2 Jun 2008 17:47:37 -0700

    >>
    >>>
    >>>I have an aspx page that is sending pdf files to client browsers: it

    > uses
    >>a filestream to read the pdf file and
    >>>response.binarywrite to send content to the browser. This has worked

    >>great for years in IE, Firefox and Opera on
    >>>windows, and it works on a Mac with Firefox and Opera. But this fails

    > in
    >>Safari with the generic message "A network
    >>>error occurred while accessing this document".
    >>>
    >>>Here is a link to try out

    >>http://www.lanecounty.org/TaxMap/ViewFile.aspx?type=TM&id=2380
    >>>
    >>>
    >>>Here is a code snippet for the page.
    >>>
    >>> switch (fi.Extension.ToLower())
    >>> {
    >>> case ".tif":
    >>> case ".tiff":
    >>> contentType = "image/tiff";
    >>> break;
    >>> case ".pdf":
    >>> contentType = "application/pdf";
    >>> break;
    >>> }
    >>>
    >>> //########################################
    >>> FileStream fs = new FileStream(imageFile, FileMode.Open);
    >>> try
    >>> {
    >>> HttpContext.Current.Response.Clear();
    >>> HttpContext.Current.Response.Buffer = true;
    >>> HttpContext.Current.Response.ContentType = contentType;
    >>>
    >>> int FileLength = System.Convert.ToInt32(fs.Length);
    >>> byte[] buffer = new byte[FileLength + 1];
    >>> fs.Read(buffer, 0, FileLength);
    >>> HttpContext.Current.Response.BinaryWrite(buffer);
    >>>
    >>> }
    >>> catch (Exception ex)
    >>> {
    >>> }
    >>> finally
    >>> {
    >>> fs.Close();
    >>> }
    >>> //########################################
    >>> HttpContext.Current.Response.Flush();
    >>>
    >>> HttpContext.Current.Response.End();
    >>>
    >>>
    >>>

    >>
    >>

    >
     
    Brad, Jun 11, 2008
    #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?S3Jpc2huYQ==?=

    Streaming Excel Content

    =?Utf-8?B?S3Jpc2huYQ==?=, Feb 24, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    1,156
    =?Utf-8?B?S3Jpc2huYQ==?=
    Feb 25, 2004
  2. Guest
    Replies:
    6
    Views:
    520
    Steven Cheng[MSFT]
    Dec 1, 2005
  3. hazz
    Replies:
    6
    Views:
    50,063
    SkyUCHC
    Jun 9, 2010
  4. Replies:
    3
    Views:
    402
    James Kanze
    Jul 25, 2007
  5. panda

    Binary streaming

    panda, Sep 26, 2006, in forum: ASP General
    Replies:
    4
    Views:
    165
    panda
    Sep 27, 2006
Loading...

Share This Page