![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
From: "Dave Bush" <davembush (AT) dmbcllc (DOT) com Subject: Re: Caching Binary Output Date: Tue, 30 Oct 2007 14:28:47 -0400 Sure, I do it all the time. The easiest way is to create an aspx page and put the caching directives in the aspx file and in the page_load event of your "code behind" put a variation of the code you have below. You will, of course, need to Clear the output stream, change the mime type, and do a Request.End() at the end of the page_load, but it definitely works. -----Original Message----- From: Chuck P [mailto:Chuck (AT) newsgroup (DOT) nospam] Posted At: Tuesday, October 30, 2007 2:07 PM Posted To: microsoft.public.dotnet.framework.aspnet.caching Conversation: Caching Binary Output Subject: Caching Binary Output I have a web page with a Button on it that when clicked displays files (doc, pdf, etc. ) that are stored in a database. Is their a way to take advantage of caching? I was wondering if an If-Modified-Since header could be used? Also are any of the caching statements necessary in my method? There are duplicate fileNames in the database! When the button is clicked the following method is executed. public static void DisplayFile(byte[] fileData, string fileName, string contentType) { HttpResponse response = HttpContext.Current.Response; response.Cache.SetExpires(DateTime.Now.AddSeconds( -1)); response.Cache.SetNoStore(); response.Cache.SetCacheability(HttpCacheability.No Cache); response.Buffer = true; response.Clear(); response.AppendHeader("Content-Disposition", "attachment;filename= \"" + fileName + "\""); response.AppendHeader("Content-Length", fileData.Length.ToString()); response.ContentType = contentType; response.OutputStream.Write(fileData, 0, fileData.Length); response.OutputStream.Flush(); response.OutputStream.Close(); response.Flush(); response.Close(); } These references got me wondering. http://aspnet.4guysfromrolla.com/dem...rticles/120606 -1.aspx http://aspnet.4guysfromrolla.com/articles/122204-1.aspx Thanks, |
#3
| |||
| |||
|
|
Sure, I do it all the time. The easiest way is to create an aspx page and put the caching directives in the aspx file and in the page_load event of your "code behind" put a variation of the code you have below. You will, of course, need to Clear the output stream, change the mime type, and do a Request.End() at the end of the page_load, but it definitely works. -----Original Message----- From: Chuck P [mailto:Chuck (AT) newsgroup (DOT) nospam] Posted At: Tuesday, October 30, 2007 2:07 PM Posted To: microsoft.public.dotnet.framework.aspnet.caching Conversation: Caching Binary Output Subject: Caching Binary Output I have a web page with a Button on it that when clicked displays files (doc, pdf, etc. ) that are stored in a database. Is their a way to take advantage of caching? I was wondering if an If-Modified-Since header could be used? Also are any of the caching statements necessary in my method? There are duplicate fileNames in the database! When the button is clicked the following method is executed. public static void DisplayFile(byte[] fileData, string fileName, string contentType) { HttpResponse response = HttpContext.Current.Response; response.Cache.SetExpires(DateTime.Now.AddSeconds( -1)); response.Cache.SetNoStore(); response.Cache.SetCacheability(HttpCacheability.No Cache); response.Buffer = true; response.Clear(); response.AppendHeader("Content-Disposition", "attachment;filename= \"" + fileName + "\""); response.AppendHeader("Content-Length", fileData.Length.ToString()); response.ContentType = contentType; response.OutputStream.Write(fileData, 0, fileData.Length); response.OutputStream.Flush(); response.OutputStream.Close(); response.Flush(); response.Close(); } These references got me wondering. http://aspnet.4guysfromrolla.com/dem.../120606-1.aspx http://aspnet.4guysfromrolla.com/articles/122204-1.aspx Thanks, |
#4
| |||
| |||
|
|
Thanks for Dave's input. Hi Chuck, The one you mentioned is client cache which is a feature of the http 1.1 protocol. The ASP.NET Cache API(which set client cache ) actually use the "Cache-Control" http header to supply the http cache information so as to let the client browser know how to cache the response content. AS in the MSDN document said, you can look up the RFCC 2616- HTTP/1.1 spec and find the detailed description on "cache-control" in section 14.9 Sincerely, Steven Cheng Microsoft MSDN Online Support Lead This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- From: "Dave Bush" <davembush (AT) dmbcllc (DOT) com Subject: Re: Caching Binary Output Date: Tue, 30 Oct 2007 14:28:47 -0400 Sure, I do it all the time. The easiest way is to create an aspx page and put the caching directives in the aspx file and in the page_load event of your "code behind" put a variation of the code you have below. You will, of course, need to Clear the output stream, change the mime type, and do a Request.End() at the end of the page_load, but it definitely works. -----Original Message----- From: Chuck P [mailto:Chuck (AT) newsgroup (DOT) nospam] Posted At: Tuesday, October 30, 2007 2:07 PM Posted To: microsoft.public.dotnet.framework.aspnet.caching Conversation: Caching Binary Output Subject: Caching Binary Output I have a web page with a Button on it that when clicked displays files (doc, pdf, etc. ) that are stored in a database. Is their a way to take advantage of caching? I was wondering if an If-Modified-Since header could be used? Also are any of the caching statements necessary in my method? There are duplicate fileNames in the database! When the button is clicked the following method is executed. public static void DisplayFile(byte[] fileData, string fileName, string contentType) { HttpResponse response = HttpContext.Current.Response; response.Cache.SetExpires(DateTime.Now.AddSeconds( -1)); response.Cache.SetNoStore(); response.Cache.SetCacheability(HttpCacheability.No Cache); response.Buffer = true; response.Clear(); response.AppendHeader("Content-Disposition", "attachment;filename= \"" + fileName + "\""); response.AppendHeader("Content-Length", fileData.Length.ToString()); response.ContentType = contentType; response.OutputStream.Write(fileData, 0, fileData.Length); response.OutputStream.Flush(); response.OutputStream.Close(); response.Flush(); response.Close(); } These references got me wondering. http://aspnet.4guysfromrolla.com/dem...rticles/120606 -1.aspx http://aspnet.4guysfromrolla.com/articles/122204-1.aspx Thanks, |
#5
| |||
| |||
|
|
Yes, and so do I. Here's a sample from returning a flash file from a database. private void Page_Load(object sender, System.EventArgs e) { Response.ClearContent(); Response.ClearHeaders(); StoreProductController spc = new StoreProductController(); DataSetStoreProduct.dmbcllcStoreProductGetRow info = spc.Get(Convert.ToInt32(Request.QueryString["id"])); Response.ContentType = "application/x-shockwave-flash"; foreach(byte b in info.Flash) Response.OutputStream.WriteByte(b); Response.End(); } The Response object you are writing to is EXACTLY the same Response object I write to. -----Original Message----- From: Chuck P [mailto:Chuck (AT) newsgroup (DOT) nospam] Posted At: Wednesday, October 31, 2007 9:58 AM Posted To: microsoft.public.dotnet.framework.aspnet.caching Conversation: Caching Binary Output Subject: Re: Caching Binary Output Dave did you note that I was streaming variable output to the response Not a URL redirect? "Dave Bush" wrote: Sure, I do it all the time. The easiest way is to create an aspx page and put the caching directives in the aspx file and in the page_load event of your "code behind" put a variation of the code you have below. You will, of course, need to Clear the output stream, change the mime type, and do a Request.End() at the end of the page_load, but it definitely works. -----Original Message----- From: Chuck P [mailto:Chuck (AT) newsgroup (DOT) nospam] Posted At: Tuesday, October 30, 2007 2:07 PM Posted To: microsoft.public.dotnet.framework.aspnet.caching Conversation: Caching Binary Output Subject: Caching Binary Output I have a web page with a Button on it that when clicked displays files (doc, pdf, etc. ) that are stored in a database. Is their a way to take advantage of caching? I was wondering if an If-Modified-Since header could be used? Also are any of the caching statements necessary in my method? There are duplicate fileNames in the database! When the button is clicked the following method is executed. public static void DisplayFile(byte[] fileData, string fileName, string contentType) { HttpResponse response = HttpContext.Current.Response; response.Cache.SetExpires(DateTime.Now.AddSeconds( -1)); response.Cache.SetNoStore(); response.Cache.SetCacheability(HttpCacheability.No Cache); response.Buffer = true; response.Clear(); response.AppendHeader("Content-Disposition", "attachment;filename= \"" + fileName + "\""); response.AppendHeader("Content-Length", fileData.Length.ToString()); response.ContentType = contentType; response.OutputStream.Write(fileData, 0, fileData.Length); response.OutputStream.Flush(); response.OutputStream.Close(); response.Flush(); response.Close(); } These references got me wondering. http://aspnet.4guysfromrolla.com/dem.../120606-1.aspx http://aspnet.4guysfromrolla.com/articles/122204-1.aspx Thanks, |
#6
| |||
| |||
|
|
From: =?Utf-8?B?Q2h1Y2sgUA==?= <Chuck (AT) newsgroup (DOT) nospam References: <9EB87EDD-E222-4135-A764-A4037A6A54DE (AT) microsoft (DOT) com B24F993B0C5F435EA114AF36874F472C@OfficeVista Subject: Re: Caching Binary Output Date: Wed, 31 Oct 2007 07:06:05 -0700 Steven, I wasn't sure from section 14.9 how the browser identifies the request for caching or if the caching works the same for various content types. Does it use the URL and any parameters but not form fields? If it uses the URL and parameters, I could change my code to not stream from the original URL but redirect to somePage.aspx?UniqueContentID=1 Which would probably get cached then (content type aapplication/x-msdownload, application/pdf )? "Steven Cheng[MSFT]" wrote: Thanks for Dave's input. Hi Chuck, The one you mentioned is client cache which is a feature of the http 1.1 protocol. The ASP.NET Cache API(which set client cache ) actually use the "Cache-Control" http header to supply the http cache information so as to let the client browser know how to cache the response content. AS in the MSDN document said, you can look up the RFCC 2616- HTTP/1.1 spec and find the detailed description on "cache-control" in section 14.9 Sincerely, Steven Cheng Microsoft MSDN Online Support Lead This posting is provided "AS IS" with no warranties, and confers no rights. |
#7
| |||
| |||
|
|
Organization: Microsoft Date: Mon, 05 Nov 2007 02:50:49 GMT Subject: Re: Caching Binary Output Thanks for your reply Chuck, Based on my understanding, the http protocol's cache is specified through some header variables in request or response header collection. Sure, url (include querystring) will influence how the client browser cache the request. Normally, a cache will be generated for a fixed url, if anything in the url changed, it will retrieve response from server. Sincerely, Steven Cheng Microsoft MSDN Online Support Lead This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- From: =?Utf-8?B?Q2h1Y2sgUA==?= <Chuck (AT) newsgroup (DOT) nospam References: <9EB87EDD-E222-4135-A764-A4037A6A54DE (AT) microsoft (DOT) com B24F993B0C5F435EA114AF36874F472C@OfficeVista Subject: Re: Caching Binary Output Date: Wed, 31 Oct 2007 07:06:05 -0700 Steven, I wasn't sure from section 14.9 how the browser identifies the request for caching or if the caching works the same for various content types. Does it use the URL and any parameters but not form fields? If it uses the URL and parameters, I could change my code to not stream from the original URL but redirect to somePage.aspx?UniqueContentID=1 Which would probably get cached then (content type aapplication/x-msdownload, application/pdf )? "Steven Cheng[MSFT]" wrote: Thanks for Dave's input. Hi Chuck, The one you mentioned is client cache which is a feature of the http 1.1 protocol. The ASP.NET Cache API(which set client cache ) actually use the "Cache-Control" http header to supply the http cache information so as to let the client browser know how to cache the response content. AS in the MSDN document said, you can look up the RFCC 2616- HTTP/1.1 spec and find the detailed description on "cache-control" in section 14.9 Sincerely, Steven Cheng Microsoft MSDN Online Support Lead This posting is provided "AS IS" with no warranties, and confers no rights. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |