How do I add a 'Last Modified' header to a .net page

Discussion in 'C#' started by LineOfSight, Dec 24, 2006.

  1. #1
    I'm trying to work out how to add the correct 'Last Modified' information to the header information returned by the server. I'm not familiar with .Net but have worked out so far that I need to a <% Response.AddHeader....... to each page. I want the 'Last Modified' information to reflect the the date and time the file was last updated.

    Can anyone point me in the right direction?
     
    LineOfSight, Dec 24, 2006 IP
  2. pushkar

    pushkar Peon

    Messages:
    125
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Store it in Session Variable may be it work fine....
     
    pushkar, Dec 25, 2006 IP
  3. kajakske

    kajakske Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    165
    #3
    The last modified header is added by your webserver to show when the file was last edited (which is what you want), however this only works on static pages, as an ASP page (and any other dynamic page) is created on the fly (caching not included) and thus has a last modified header of the current time.

    I wouldn't advice to change this header into the time you last modified the ASP code, since this has no real value, and would make different pages be cached while they shouldn't ...

    What exactly would you like to have? If you want an indication of the time your site was last updated, this is easily done with a timestamp in the database ...
     
    kajakske, Dec 26, 2006 IP
  4. LineOfSight

    LineOfSight The Doctor

    Messages:
    125
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The site does not run a database. What I would like is to get the current updated date of a file (of each page within the site) e.g. so if I've made a change to the home page the updated date would be different to that of other pages within the site). I want this statment as dynamic as possible (no hard coded page names) so I can use it as an include on each page. I then want to then use that variable returned in the header information as the Last-modified date.

    This should work but when I run it I first get an error saying 'thisfile' not declared and after that an error saying that 'let' & 'set' have been depreciated. I'm running the latest version of .NET but it's not a scripting language I'm familiar with.

    Thanks
     
    LineOfSight, Dec 26, 2006 IP
  5. kajakske

    kajakske Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    165
    #5
    Well, there are obviously some errors in the code, I believe it was meant to be used as ASP code (the old ASP) ...

    "'thisfile' not declared "
    "Dim thisfile" somewhere before using it should fix that (old style ASP)

    "set fs = nothing: set fso = nothing "
    That's completely wrong code change it to
    "set fs = nothing
    set fso = nothing " old style ASP code
     
    kajakske, Dec 27, 2006 IP
  6. LineOfSight

    LineOfSight The Doctor

    Messages:
    125
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Excellent - thanks for your help :)
     
    LineOfSight, Dec 27, 2006 IP