Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing content expiry in subdirectory

Status
Not open for further replies.

rockyprince

Programmer
Aug 11, 2004
4
GB
I'm running IIS5.0 on Windows 2000, and have encountered a problem when trying to script changes to the content expiration setting on a sub-directory, within a virtual directory.

Basically, I have a website with an images directory, which I would like to cache for 28 days (only want to chahe the images dir and nothing else).
For this to work, I had to turn on Content Expiration on the top level website, and set it to "Expire Immediately". This is then propigated down the entire website structure.
Then I need to get a handle on the sub-directory and change it's settings.

My problem happens when I try to script a change to the images directory, to change the expiry to 28 days, like this:

Set vDir = GetObject("IIS://LocalHost/w3svc/1/root/images")
vDir.Put "HTTPEXPIRES", "D,2419200"
vDir.SetInfo

This piece of script simply does nothing when I run it.

HOWEVER (and here's the strange bit), if I manually go into IIS, and change the images directory to be a virtual directory, then immediately change it back (ie click CREATE then REMOVE), and run the script, then the changes top the expiry date are implemented.

This seems very strange to me, can anyone shed any light on it?
It seems that I can't script a change to the content expiry section of a sub-directory, unless it was a virtual directory at some stage in it's life.

thanks for any help,
Rory
 
I have since discovered what the problem was.

When I was doing a GetObject, it wasn't acually finding anything. I believe this is due to there being no entry in the Metabase.

As a result I changed my script to look like this:

Set vDir = GetObject("IIS://LocalHost/w3svc/1/root/images")
If err.number <> 0 Then
Set objRoot = GetObject("IIS://LocalHost/w3svc/1/root")
Set vDir = objRoot.Create("IIsWebDirectory", "images")
End If
vDir.Put "HTTPEXPIRES", "D,2419200"
vDir.SetInfo


This now works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top