473,785 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to set HttpExpires property on a folder within a virtual directory?

Hi,

My requirement is as follows:
I need to set the HttpExpires (enable content expiration - set to 7 days) on
a folder within a virtual directory.

I have been able to set the HttpExpires property on a virtual directory
using the following code:

DirectoryEntry myVdPath = new
DirectoryEntry( "IIS://localhost/W3SVC/1/Root/<virtual directory>");
myVdPath.Refres hCache();
myVdPath.Proper ties["HttpExpire s"].Value = "D, 604800"; //Content expiration
after 7 days
myVdPath.Commit Changes();

But, if I modify the path and use "IIS://localhost/W3SVC/1/Root/<virtual
directory>/<directory on which the property is to be set>", then it throws
the following exception:

An unhandled exception of type 'System.Runtime .InteropService s.COMException'
occurred in system.director yservices.dll

Additional information: The system cannot find the path specified

Regards,

Shailesh Patel
Sep 3 '07 #1
6 4349
Hello Walter,

Thanks for your quick response.

I am getting the following exception when I try to access the folder within
a virtual directory.

"An unhandled exception of type 'System.IO.Dire ctoryNotFoundEx ception'
occurred in system.director yservices.dll
Additional information: The system cannot find the path specified."

The following code was used:

DirectoryEntry myVdPath = new
DirectoryEntry( "IIS://localhost/W3SVC/1/Root/<virtual directory name>");
myVdPath.Refres hCache();
DirectoryEntry mySubDirPath = myVdPath.Childr en.Find("bin",
"IIsWebDirector y");
mySubDirPath.Re freshCache();

The exception is thrown at line #3 (DirectoryEntry mySubDirPath =
myVdPath...).
I have also tried using "IIsWebVirtualD ir" instead of "IIsWebDirector y" and
even defined just the folder name in the Find method,
but no success yet on this issue.

Regards,

Shailesh Patel
Sep 5 '07 #2
Hi Shailesh,

Could you please check if the "bin" subfolder exists in the virtual
directory? For example: if we're open
"IIS://localhost/W3SVC/1/Root/WebSite1" and it's mapped to physical folder
"c:\inetpub\www root\WebSite1" on the IIS server, make sure the folder
"c:\inetpub\www root\Website1\b in" exists.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 5 '07 #3
Hi Shailesh,

Have you seen my above reply? Please feel free to let me know if there's
anything unclear. Thanks.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 10 '07 #4
Hi Walter,

As per your suggestion, I tried to access the "bin" folder contained within
a virtual directory.

First, I tried to access the bin folder for a sample project "Sample" which
is stored at physical location "C:\Inetpub\www root\Sample" and
has the following path in IIS - "IIS://localhost/W3SVC/1/ROOT/Sample". In
this case, it worked fine and I was able to set the "HttpExpire s" property
on the "bin" folder.

But, I want to access the folder and set "HttpExpire s" property on a folder
which is stored in a virtual directory within a parent virtual directory.

Hence, in IIS the virtual directories are displayed as:

Default Web Site
-- MainProject (virtual directory) (physical path -
C:\Inetpub\wwwr oot\SampleProje ct\Site\MainPro ject)
---- SubProjects (folder)
------ Project1 (another virtual directory) (physical path -
C:\Inetpub\wwwr oot\SampleProje ct\Site\MainPro ject\SubProject s\Project1)
-------- images (folder on which the HttpExpires property is to be set)

The "MainProjec t" virtual directory was created using IIS Manager and
"Project1" virtual directory is created using a web application.

I can access both the virtual directory using the following code:

DirectoryEntry myVdPath = new
DirectoryEntry( "IIS://localhost/W3SVC/1/ROOT/MainProject");
myVdPath.Refres hCache();

and

DirectoryEntry myVdPath = new
DirectoryEntry( "IIS://localhost/W3SVC/1/ROOT/MainProject/SubProjects/Project1");
myVdPath.Refres hCache();

But, when I try to access "images" folder within it, the following error is
thrown:

An unhandled exception of type 'System.Runtime .InteropService s.COMException'
occurred in system.director yservices.dll
Additional information: Exception from HRESULT: 0x80005008.

Regards,

Shailesh Patel
Sep 10 '07 #5
Hi Shailesh,

Sorry, I forgot to mention that the metabase record for a web directory is
not always present in the IIS metabase database. My previous example is
accidentally using the 'bin' directory which happen to have already created
that record.

We need to first to check if it exists or not, if not, then we need to
create it:
static void test2()
{
DirectoryEntry vd1 = new
DirectoryEntry( "IIS://wawangvsrv1/W3SVC/1/Root/RoundedCorner/bin/_vti_cnf");
vd1.RefreshCach e();

DirectoryEntry deChild = null;
foreach (DirectoryEntry de in vd1.Children)
{
if (de.Name.ToLowe r() == "abc" && de.SchemaClassN ame ==
"IIsWebDirector y")
{
deChild = de;
break;
}
}

if (deChild == null)
{
deChild = vd1.Children.Ad d("abc", "IIsWebDirector y");
vd1.CommitChang es();
}

deChild.Propert ies["HttpExpire s"].Value = "D, 604800";
//Content expiration after 7 days
deChild.CommitC hanges();
}
To inspect the IIS metabase database, you can try IIS Metabase Explorer:

#The IIS 6.0 Resource Kit Tools
http://support.microsoft.com/kb/840671
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 11 '07 #6
Hi Walter,

Thank you Walter, for your help in solving this issue and the sample code.

Regards,

Shailesh Patel
Sep 12 '07 #7

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

Similar topics

2
2107
by: | last post by:
Let me explain step wise. 1.. I have a site running on port 5555 2.. If contains web.config file with contains <Forms> authentication. 3.. The site contains a sub-folder named "MembersArea" which contains ss.aspx 4.. ss.aspx contains page_load event which prints Response.Write(Page.User.Identity.Name); 5.. Everything work proper untill here 6.. Now i want to have one more web.config file for folder "MembersArea" , I know i just...
0
1073
by: NoOne | last post by:
This is pissing me off. The web app setup project is great except for one stupid limitiation. You can't specify the target directory for the virtual folder. What is up with that? I've been reading posts and documentation that it works that way by design, and I'm having a hard time believing there isn't a workaround for this. What I need is very simple. You have the following options in a Web App setup UI dialog * Port
1
2210
by: Tai Ming | last post by:
Hi I am trying to create an asp.net application (using Visual Studio.net 2002 on an xpPro machine). However, I need the application to be created in a folder somewhere other than in wwwroot (this is very important as some sometimes we have to install our software in specific places Is there any way to set VS to do this automatically? I have been trying for hours now to do this. I have created a virtual directory in IIS and pointed it to a...
2
649
by: MurrayTh | last post by:
Instead of having a copy of the aspnet_client folder in each site's files on a machine, can a virtual directory/application be made with each site's root in IIS to the machine's c:\inetpub\wwwroot\aspnet_client folder? Would this create security issues? If it is OK to do this, should it be a virtual directory or virtual application?
10
2160
by: Tony Abate | last post by:
I am working on an ASP.NET app that is going well except for one thing. I build my application and then move the .aspx file to a different directory. I can point the Codebehind property back to the .aspx.vb file in the original directory, but cannot do so with the Inherits property. I know one solution is to place the DLL file in the new directory with my .aspx file, but I would like to avoid this as it would require me to update all the...
8
1734
by: supasnail | last post by:
I have a happily working set of asp pages which read from the database via include file "./_private/include/database.mdb". However, when I try to gain access to this database on pages one folder removed using "../_private/include/database.mdb", the pages won't display. This whole system works fine on my home test server (iis.5.0), but 'breaks' when uploaded to the public server. I know the path to database is correct because the upper...
2
6683
by: Alex | last post by:
Hello, I'm creating a program to parse a directory and all files within that directory (including subdirectories), but 'directoryinfo' only parses the current directory. Is it possible to have it process all files within subdirectories as well? Thanks -- Alex
5
7347
by: OK | last post by:
I am using an image control to display some images within a virtual map (ImagesRoot in IIS) outside of the web root in my vb asp.net application. How should I code the imageurl property to have this working? Image1.imageurl = ?
6
3532
by: Scott M. | last post by:
I didn't get a resolution to this in my earlier post, so I'll try again: System: Windows XP Pro. (SP2) with IIS installed and running PRIOR to VS 2008 Pro. installation. VS 2008 Pro. (full installation). Installations and testing is all done via an Administrator account. If I simply create a new ASP .NET Web Application Project (WAP) on my local
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8979
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.