473,320 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using If-Modified-Since Http Header

Hi,

I've been reading the <a href="http://www.google.com/webmasters/guidelines.html">Google WebMaster
Guidelines. Google urges web developers to make use of the If-Modified-Since http header with an
emphasis on saving bandwidth and overhead.

How do I use this header in ASP.NET? Is it there by default or must I explicitly place it in the
Headers collection? How would I inform the GoogleBot of this information?

Thanks,
Roshawn
Nov 19 '05 #1
4 3195
See a running sample at : http://aspnet.asp101.com/samples/modified.aspx

Pick up the code at : http://www.asp101.com/samples/modified_aspx.zip

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Roshawn Dawson" <ud****@bellsouth.net> wrote in message
news:ON****************@TK2MSFTNGP12.phx.gbl...
Hi,

I've been reading the <a href="http://www.google.com/webmasters/guidelines.html">Google
WebMaster Guidelines. Google urges web developers to make use of the If-Modified-Since
http header with an emphasis on saving bandwidth and overhead.

How do I use this header in ASP.NET? Is it there by default or must I explicitly place
it in the Headers collection? How would I inform the GoogleBot of this information?

Thanks,
Roshawn

Nov 19 '05 #2
Additional info at :

http://www.tutorialized.com/tutorial...-ASP.Net./9068

Here's sample code :

Dim dtNowUnc As DateTime = DateTime.Now().ToUniversalTime
Dim sDtModHdr = Request.Headers.Get("If-Modified-Since")
' does header contain If-Modified-Since?
If (sDtModHdr <> "") And IsDate(sDtModHdr) Then
' convert to UNC date
Dim dtModHdrUnc As DateTime = Convert.ToDateTime(sDtModHdr).ToUniversalTime
' if it was within the last 15 minutes, return 304 and exit
If DateTime.Compare(dtModHdrUnc, dtNowUnc.AddMinutes(-15)) > 0 Then
Response.StatusCode = 304
Response.End()
Exit Sub
End If
End If
' add Last-modified to header - FeedDemon stores this with cached
' feed so it's passed to the server the next time the feed is updated
Response.AddHeader("Last-modified", dtNowUnc.ToString("r"))

Picked up from :

http://nick.typepad.com/blog/2004/09...ndwidth_c.html

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:uV*************@TK2MSFTNGP09.phx.gbl...
See a running sample at : http://aspnet.asp101.com/samples/modified.aspx

Pick up the code at : http://www.asp101.com/samples/modified_aspx.zip

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Roshawn Dawson" <ud****@bellsouth.net> wrote in message
news:ON****************@TK2MSFTNGP12.phx.gbl...
Hi,

I've been reading the <a href="http://www.google.com/webmasters/guidelines.html">Google
WebMaster Guidelines. Google urges web developers to make use of the If-Modified-Since
http header with an emphasis on saving bandwidth and overhead.

How do I use this header in ASP.NET? Is it there by default or must I explicitly place
it in the Headers collection? How would I inform the GoogleBot of this information?

Thanks,
Roshawn



Nov 19 '05 #3
Thanks Juan. Nice references!! :-)

Juan T. Llibre wrote:
Additional info at :

http://www.tutorialized.com/tutorial...-ASP.Net./9068

Here's sample code :

Dim dtNowUnc As DateTime = DateTime.Now().ToUniversalTime
Dim sDtModHdr = Request.Headers.Get("If-Modified-Since")
' does header contain If-Modified-Since?
If (sDtModHdr <> "") And IsDate(sDtModHdr) Then
' convert to UNC date
Dim dtModHdrUnc As DateTime = Convert.ToDateTime(sDtModHdr).ToUniversalTime
' if it was within the last 15 minutes, return 304 and exit
If DateTime.Compare(dtModHdrUnc, dtNowUnc.AddMinutes(-15)) > 0 Then
Response.StatusCode = 304
Response.End()
Exit Sub
End If
End If
' add Last-modified to header - FeedDemon stores this with cached
' feed so it's passed to the server the next time the feed is updated
Response.AddHeader("Last-modified", dtNowUnc.ToString("r"))

Picked up from :

http://nick.typepad.com/blog/2004/09...ndwidth_c.html

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:uV*************@TK2MSFTNGP09.phx.gbl...
See a running sample at : http://aspnet.asp101.com/samples/modified.aspx

Pick up the code at : http://www.asp101.com/samples/modified_aspx.zip

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Roshawn Dawson" <ud****@bellsouth.net> wrote in message
news:ON****************@TK2MSFTNGP12.phx.gbl.. .
Hi,

I've been reading the <a href="http://www.google.com/webmasters/guidelines.html">Google
WebMaster Guidelines. Google urges web developers to make use of the If-Modified-Since
http header with an emphasis on saving bandwidth and overhead.

How do I use this header in ASP.NET? Is it there by default or must I explicitly place
it in the Headers collection? How would I inform the GoogleBot of this information?

Thanks,
Roshawn



Nov 19 '05 #4
Roshawn Dawson wrote:
Hi,

I've been reading the <a
href="http://www.google.com/webmasters/guidelines.html">Google
WebMaster Guidelines. Google urges web developers to make use of the
If-Modified-Since http header with an emphasis on saving bandwidth
and overhead.

How do I use this header in ASP.NET? Is it there by default or must
I explicitly place it in the Headers collection? How would I inform
the GoogleBot of this information?


Note that in addition to Juan's code-based approach where *you* do all
the work, there's also an easier way: Let infrastructure work its magic.

All you need to do is allow caching of your pages by applying the HTTP
headers "Cache-Control: max-age" and "Expires" (for HTTP 1.0
compatibility).

Setting these headets can be done in code, via page directives or by
configuring your web server to do it.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ben Jessel | last post by:
I am in the process of converting my site to using XHTML and CSS. A lot of my sites include tables of data, which are highlighted using javascript rollovers. I have converted my a lot of my...
0
by: grutta | last post by:
I am writing a windows service that will recieve notification when a USB Device is insterted into the machine. I have used the RegisterDeviceNotification and the RegisterServiceCtrlHandlerEx with...
2
by: rawCoder | last post by:
Hi All, I have a *.cer file, a public key of some one and I want to encrypt some thing using this public key. Can someone point me to a sample code for Encrypting some file using...
17
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example ...
8
by: Douglas | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hello, The following code does not compile if line 3 is uncommented "using namespace std". I do not understand it. Could...
12
by: Calum Grant | last post by:
In older C++ computer books, you'll often see using namespace std; even in my 1996 copy of Stroustrup. Nowadays, it seems to be considered better to qualify names to make it clearer what...
3
by: Imre | last post by:
As far as I know, the using directive is transitive, and I'm not sure I like this. So I'd like to ask if there's any workaround. Consider this: namespace MyNameSpace { void...
1
by: Dan Kelley | last post by:
I have 2 projects - 1 Winform project that sends Udp messages using the UdpClient class when a button is clicked, and a Console application that listens for these Udp messages. If I try to use...
6
by: Nathan Kovac | last post by:
Yesterday afternoon I was getting the following errors in a windows service: 'DatabaseManager.DataComponent', 'Error', '3 Errors: Line: 0 - Metadata file 'ScriptingMethods.dll' could not be found...
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.