Administering an ISP Installation |
The following sample ASP pages show you how to set up customized scripts. The first deals with setting permissions in general, while the second shows you how to set up a virtual directory with Read, Script only, and Directory browsing permission.
Web server permissions control how users access and interact with specific FTP and Web sites. For example, permissions determine whether users visiting a Web site are allowed to see a particular page, upload information, or run scripts on the site. Unlike NTFS permissions, Web server permissions apply to all users accessing a Web or FTP site. This distinction is very important, because NTFS permissions apply only to a specific user or group of users with a valid Windows account.
The following example contains customized scripts that set permissions on a virtual directory in two ways:
The example also shows how inheritance works. In the first part, the GET/PUT notation denies Write permission (sets it to FALSE) from the root level of the default Web site on MyComputer. When you set permissions at the root level, all directories below the root level inherit this setting. However, the dot notation (the second part of the example) grants Write permission (sets it to TRUE) on the virtual directory named VDir1a, overwriting the inherited setting that is at the root level.
<%
Dim WebServerRootObj
Dim VDirObj
Dim WritePerm
'Open the object for the first virtual Web server root.
Set WebServerRootObj = GetObject("IIS://MyComputer/W3SVC/1/Root")
'Deny write access for all directories and files
'for the server (except those already specifically set)
'Using the Put method.
WebServerRootObj.Put "AccessWrite", False
'Save the changed value to the metabase.
WebServerRootObj.SetInfo
'Get a directory subordinate to the Web server root.
Set VDirObj = GetObject("IIS://MyComputer/W3SVC/1/Root/Vdir1/VDir1a")
'Overwrite the inherited value for write access
'Using the dot method equivalent to Put.
VDirObj.AccessWrite = True
'Save the changed value to the metabase.
VDirObj.SetInfo
%>
The next example shows a customized script that creates a virtual directory with Read, Script only, and Directory browsing permissions.
<%
'''''''''''''''''''''''''''''''''
'ADSI ASP Sample Program.
'This is a sample of how to create a virtual directory using ADSI.
'
'''''''''''''''''''''''''''''''''
Option Explicit
On Error Resume Next
'''''''''''''''''''''''
'First, open the path to the Web server you are
'trying to add a vdir to.
Dim ServObj
Dim VdirObj
Dim Testpath
Set ServObj = GetObject("IIS://LocalHost/w3svc/1/Root")
if (Err <>0) then
Response.Write "GetObject (""IIS://LocalHost/w3svc/1/Root"") Failed! <BR>"
Response.Write "Error! " & Err.Number & "(" & Hex(Err.Number) & "): " & Err.Description & "<BR>"
Response.End
end if
'''''''''''''''''''''''
'Second, Create the vdir path.
Set VdirObj = ServObj.Create("IIsWebVirtualDir", "MyVdir")
VdirObj.SetInfo
if (Err<>0) then
Response.Write "CreateObject (""IIS://LocalHost/w3svc/1/Root/MyVdir"") Failed!<BR>"
Response.Write "Error! " & Err.Number & "(" & Hex (Err.Number) & "): " & Err.Description &
"<BR>"
Response.End
end if
''''''''''''''''''''''''
'Finally, create a Path variable containing the VR path and
'set the permissions to read, script, and directory browsing.
VdirObj.AccessRead = True
VdirObj.AccessScript = True
VdirObj.EnableDirBrowsing = True
Testpath = "C:\Temp"
VdirObj.Put "Path", (Testpath)
VdirObj.SetInfo
if (Err<> 0) then
Response.Write "Put (""Path"") Failed!"
Response.Write "Error! " & Err.Number & "(" & Hex (Err.Number) & "): " & Err.Description &
"<BR>"
Response.End
end if
Response.Write "VDIR successfully created"
''''''''''''''''''''''''
'The minimum amount necessary to create a virtual directory has now
'been completed. If you need to add more, do it here.
%>
For more sample scripts and for details on writing your own scripts, see the “Programmatic Administration Examples” topic in the IIS 5.0 online product documentation.