Geeks With Blogs
Woodbase Godot - Blender - .Net - C# - Game Development
After struggling several hours with a problem that seemed complex, it's time for me to write a short little post about it.

I created a website the displays a list of PDF documents on one side and on select displays the document in an iframe. All seemed pretty straight forward and functional, so putting it into production I wasn't expecting any problems. But oh boy was I wrong!

The solution is farely simple loading the document into the frame with Response.BinaryWrite from the source page:

var buffer = destination.GetBuffer();
        Response.Buffer = false; //transmitfile self buffers
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-length", buffer.Length.ToString());
        Response.BinaryWrite(buffer);

This all worked nicely - even in the production environment servers, when you visited them directly! But introducing the load balancer, IE threw an "Navigation cancelled" exception. The Google Chrome browser display it as perfectly. But since the customer requirement was IE I had to find a solution.

Remember to close your door...
So after browsing through various sites on load balance configuration settings, sticky sessions, cookie solution etc. I finally took a deep breath and looked at my code again, thinking I would have to write it all over.

And then it hit me... When we use files, streams and other connections, they have to be closed! So after struggling in all directions for hours! All I really had to do was to terminate my code nicely...

Adding Response.End() solved the problem! After sending the response I now finish of correctly and everything is good.

However... Why it worked when I didn't have load balancing... I don't know...
Posted on Friday, January 22, 2016 2:29 PM ASP.NET , Software Architecture , pdf | Back to top


Comments on this post: Remember the end..

# re: Remember the end..
Requesting Gravatar...
Nice idea here. I'll try to use this process. Thanks for sharing. - Thomas W. Nabors DDS
Left by Matthew on Apr 15, 2016 12:02 AM

Your comment:
 (will show your gravatar)


Copyright © woodbase | Powered by: GeeksWithBlogs.net