ADSI Code needed to modify website properties in IIS

Hello,

I am looking for ADSI code written in vbscript (ASP) that would allow me to modify the directory properties for a certain directory in a website in IIS.

Usually, in IIS the Home Directory tab, in the folder properties, the option "The designated directory" is chosen. I want to change that to "a redirection to a URL". I want the code to act based upon the website, the directory, and the URL i want that directory to forward to.

Please make sure that the code is functional and bug free, I am willing to work with you in order to debug and achieve the desired objective of the code.
brkonthruAsked:
Who is Participating?
 
lavinderConnect With a Mentor Commented:
Hi

 here is the code to create a virtual directory

Dim oIIS, oDir
Set oIIS = GetObject("IIS://localhost/W3SVC/1/Root")
On Error Resume Next
Set oDir = oIIS.GetObject("IISWebVirtualDir", sName)
' This will return error -2147024893 if it doesn't exist
If Err.Number <> 0 Then Set oDir = oIIS.Create("IISWebVirtualDir", sName)
Err.Clear
oDir.AccessScript = True
oDir.Path = yourpath
oDir.SetInfo
oDir.AppCreate True
oDir.SetInfo
Set oDir = Nothing
Set oIIS = Nothing

cheers!!
0
 
lavinderCommented:
Hi

 here is the code

<%
 dim objdir
 set objdir=getobject("IIS://Localserver/W3SVC/1/Root/yourvirtualfolder")
 objdir.httpredirect="http://www.google.com"
 objdir.setinfo
 set objdir=nothing
%>

cheers!!
0
 
brkonthruAuthor Commented:
Hello lavinder,

Thanks for the code, ill give it a shot and get back to you.  But how would I change the site back to its original properties when it used to point to a physical directory on a drive ?


Thanks,
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
lavinderCommented:
objdir.path="whateverpathyouwant"
0
 
brkonthruAuthor Commented:
Hello lavinder,

Thanks for the code, ill give it a shot and get back to you.  But how would I change the site back to its original properties when it used to point to a physical directory on a drive ?


Thanks,
0
 
brkonthruAuthor Commented:
im not sure why the double post happend!


The code you gave me seems to only apply to virtual directories, and not physical directories under that site. Is it possible to accomplish that ?

Thanks,
0
 
lavinderCommented:
Hey friend,

 how you will access the physical directories using http protocol ? I think you should create a virtual directory for them and use them.

cheers!!
0
 
brkonthruAuthor Commented:
I think you misunderstood me, I have a site that is set to a certain directory in IIS. Lets assume its "c:\site".  This directory has several other directories underneath it, for example, it has "c:\site\d1", so when i enter site.com/d1 , it will automatically go to that physical directory under that site.

What I need to do, is the piece of code where I would be able to change the direction to "site.com/d1=c:\site\d1" to a URL that is completely different, such as "http://www.google.com".  It can be done using the GUI interface in IIS, there must be a way to do it in ADSI
0
 
lavinderCommented:
Hi

 As far as i know you can access a directory in IIS only if it exists in the metabase. IIS GUI must be showing the directories underneath your c:/site directory, but those child directories do not exist in the metabase, that is why you are not able to access the directory underneath c:/site. To solve your problem, simply set the "httpredirect" property of c:/site/d1 folder through the statements shown in previous posts. It will work, i have tested it on my machine. Earlier my machine was also not showing the folders underneath a particular site in the metabase, but when i set the "httpredirect" property of the folder underneath the site, it worked and also shown an entry in the metabase.

cheers!!
0
 
brkonthruAuthor Commented:
Im not sure I follow you, you say "simply set the "httpredirect" property of c:/site/d1 folder through the statements shown in previous posts" but I have tried what you have given me in the previous post and it didnt work, it gave me an error '80070003'.

That is why I mentioned that i need something that applies to physical directories and not virtual ones.


Thanks,
0
 
lavinderCommented:
Hi

 80070003 error is path not found, can you paste the physical/virtual directory hierarchy here and the code also.

http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q238956

cheers!!
0
 
brkonthruAuthor Commented:
Here is your code modified:

dim objdir
set objdir=getobject("IIS://devserver/W3SVC/2/root/gpziblog")
objdir.httpredirect="http://www.google.com"
objdir.setinfo
set objdir=nothing


now "gpziblog" does exist as a physical directory under the site, not as a virtual directory.  When I execute the code, i get the path not found error '80070003'
0
 
lavinderCommented:
Ok, yes it'll give "path not found error" because http is unable to recognise physical folders, therefore you will have to create a virtual directory for it.
0
 
lavinderCommented:
Probably this link might be helpful to you:
http://www.4guysfromrolla.com/webtech/022300-1.shtml
0
 
brkonthruAuthor Commented:
Appreciate your followup,

Since this is doable from the GUI interface, there must be a way to do it through ADSI.  I think in the GUI when the HttpRedirect is set, its first converted to a virtual directory, then the httpredirect is set.

So I think its possible to do this in ADSI also, setup/convert the physical directory to a virtual in the site and then apply the httpredirect, can this be done ADSI ?
0
 
brkonthruAuthor Commented:
Appreciate your followup,

Since this is doable from the GUI interface, there must be a way to do it through ADSI.  I think in the GUI when the HttpRedirect is set, its first converted to a virtual directory, then the httpredirect is set.

So I think its possible to do this in ADSI also, setup/convert the physical directory to a virtual in the site and then apply the httpredirect, can this be done ADSI ?
0
 
lavinderCommented:
can you explain giving grade "B" ?
0
All Courses

From novice to tech pro — start learning today.