Implementing virtual Directories in IIS using ADSI programming

Source: Internet
Author: User
Tags class definition iis table name trim

The conn.asp no longer posted.
This reads the directory name from the database


<!--#include file= "conn.asp"-->
<%
' Response.End '//This is used for debugging.
On Error Resume Next
Set rs=server.createobject ("ADODB. Recordset ")
Rs.activeconnection = myconnection
Sql= "SELECT * from your table name where you specify the condition"
Rs.Open sql,,1,2
If rs.eof Then response.end '////If no record is met, stop
Rs.movefirst
Dim Namestr '//define virtual directory name variable
Do as not rs.eof
If InStr (1,namestr,server.htmlencode) (Trim (Rs ("Suname"))) <>0 Then Rs.movenext
Name=name&server.htmlencode (Trim (Rs ("Suname"))
%>
<%
Scomputer = "localhost"
Sphydir = "X:\test\" & Server.HTMLEncode (Trim (Rs ("Suname")) '//here defines the physical path that the virtual directory points to
Svirdir = Server.HTMLEncode (Trim (Rs ("Suname")) '//here defines the virtual directory name
Set websvc = GetObject ("iis://" & Scomputer & "/W3SVC/1") '//Get your current site object. If there are more than one site, then the change behind 1 for 2,3 ... can point to the other
Set vRoot = Websvc. GetObject ("IIsWebVirtualDir", "root") '//Get current site virtual Root
Set classdefinition = GetObject (Vroot.schema) '//Get class definition of virtual directory
Asmusthaves = Classdefinition.mandatoryproperties
Asmayhaves = Classdefinition.optionalproperties
I=1
%>
<table border=1>
<tr><th>class must Have property</th>
<th>root Virtual Directory Current value</th></tr>
<%
On Error Resume Next

For each Thing in asmusthaves
Response.Write "<tr><td> (" & Cstr (i) & ")" &_
Thing & "</td><td>" & Vroot.get (Thing) &_
"</td></tr>"
i = i + 1
Next
%>
</table>


<table border=1>
<tr><th>class May Have property</th>
<th> Current Site </th></tr>
<%
I=1
For each Thing in asmayhaves
Response.Write "<tr><td> (" & CStr (i) & ")" &_
Thing & "</td><td>" & Vroot.get (Thing) &_
"</td></tr>"
i = i + 1
Next
On Error Goto 0

'//Create virtual directory
Response.Write Svirdir & "
"
Set VDir = vroot.create ("IIsWebVirtualDir", Svirdir)

'//Set the two properties of the virtual directory, where you set the readable properties and point the path of the virtual directory to the physical path
Vdir.accessread = True
Vdir.path = Sphydir
Vdir.setinfo '//write the information into storage, referring to the IIS site-related libraries, not your user datasheet
%>

<%
Rs.movenext
Loop
Rs.close
Response.Write "Create a virtual directory complete!"
%>

In addition, the use of ADSI for site settings such as site, delete site, configure site IP, host header, default document and so on, there is no download, interested friends can go to the Microsoft site to download ADSISDK development documents in-depth.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.