yaodong

yaodong
随笔 - 20, 评论 - 367, 引用 - 53

导航

标签

每月存档

最新留言

广告

 

使用.NET的目录服务就可以访问IIS的设置,添加虚拟目录其实就是创建一个DirectoryEntry
复杂的在于DirectoryEntry的属性,其实就是虚拟目的一些配置,比如,权限,是否要log,应用程序名等
Properties非常多,而且文档不太好找
详细可以参考MSDN以下内容
help://MS.MSDNQTR.2004JUL.1033/iissdk/iis/configuring_properties_in_the_iis_user_interface.htm

代码示例:

   const String constIISWebSiteRoot = "IIS://localhost/W3SVC/1/ROOT";

   DirectoryEntry root = new DirectoryEntry(constIISWebSiteRoot);
   DirectoryEntry entry = new DirectoryEntry(constIISWebSiteRoot + "/" + virtualDirName);

   DirectoryEntry tbEntry = root.Children.Add(virtualDirName, "IIsWebVirtualDir");

   //must be end with a '\'
   tbEntry.Properties["Path"][0] = virtualDirPath;
   tbEntry.Invoke("AppCreate",true);
   tbEntry.Properties["AccessRead"][0] = true;
   tbEntry.Properties["ContentIndexed"][0] = false;
   tbEntry.Properties["DefaultDoc"][0] = "index.asp";
   tbEntry.Properties["AppFriendlyName"][0] = virtualDirName;
   tbEntry.Properties["AppIsolated"][0] = 2;
   tbEntry.Properties["AccessScript"][0] = true;   
   tbEntry.Properties["DontLog"][0] = true;   
   
   tbEntry.CommitChanges();

打印 | 张贴于 2004-11-05 16:46:00 | Tag:暂无标签

留言反馈

#re: 用.NET在IIS中创建虚拟目录 编辑
主要用的是CreateNewSite方法

Set websvc = GetObject("IIS://"& oComputer &"/W3SVC")

SiteID = websvc.CreateNewSite (WComment, Bindings, "C:\Inetpub\Wwwroot")
2005-10-24 21:07:00 | [匿名用户:Jerry]
#re: 用.NET在IIS中创建虚拟目录 编辑
我用asp可以生成虚拟目录和站点,可以跟我联系QQ:287684
2005-10-24 21:03:00 | [匿名用户:Jerry]
#re: 用.NET在IIS中创建虚拟目录 编辑
我要创建我的相册
2005-10-21 01:22:00 | [匿名用户:zhou bu fa ]
#re: 用.NET在IIS中创建虚拟目录 编辑
IIS6(win2003 server)可建立多个站点,那么怎样才能取得每个站点的信息?IIS://localhost/W3SVC/1/Root只能取得默认的第一个站点路径。所以我在遍历本地IIS中所有的站点和虚拟目录时只能取得默认的站点信息。
请高手指点。
2005-08-22 23:53:00 | [匿名用户:Leonic]
#re: 用.NET在IIS中创建虚拟目录 编辑
但又如何新建站点呢?
2005-06-07 17:04:00 | [匿名用户:江大鱼]
#re:用.NET在IIS中创建虚拟目录 编辑
^_~,pretty good!csharpsseeoo
2005-05-18 20:36:00 | [匿名用户:X射线测量仪]
#re:用.NET在IIS中创建虚拟目录 编辑
^_^,Pretty Good!
2005-04-16 08:21:00 | [匿名用户:广播综合测试仪]
#re:用.NET在IIS中创建虚拟目录 编辑
^_^,Pretty Good!
2005-04-10 20:25:00 | [匿名用户:流变仪]
#re: 用.NET在IIS中创建虚拟目录 编辑
?
2005-01-06 20:34:00 | [匿名用户:11]
#re: 用.NET在IIS中创建虚拟目录 编辑
以前我也是在C#中调用VBS,但是每次都弹出来一个黑窗体,不知道怎么去调,郁闷呀。。。。。
2004-11-08 10:54:00 | [匿名用户:twodays]
#re: 用.NET在IIS中创建虚拟目录 编辑
那么怎样建立映射呢?
2004-11-05 18:30:00 | [匿名用户:beautyispower]
#re: 用.NET在IIS中创建虚拟目录 编辑
可惜,.NET Framework 的默认权限设置,这些代码只能在本机的 Windows Forms 中用,不能在 Web Forms 里用。(这是默认的情形,需要和主机服务提供商联系配置)

很想在 Web Forms 用这些代码,很早以前就有这个念头了。
2004-11-05 17:46:00 | [匿名用户:破宝]
#re: 用.NET在IIS中创建虚拟目录 编辑
用CSharp重写C:\Inetpub\AdminScripts\mkwebdir.vbs就可以了

或者索性直接call 这个vbs。我忘记了,反正有个文档说过如何在csharp里面调用vbs的。

当然,用ProcessStart好像也是可以的

2004-11-05 16:57:00 | [匿名用户:mvm]
#re: 用.NET在IIS中创建虚拟目录 编辑
'i used to the windows script.

Set shell = Wscript.CreateObject( "WScript.Shell" )

If Wscript.Arguments.Count < 2 Then
usage = "USAGE: theVbs virtual_directory_name directory_location_to_map"
WScript.Echo usage
Wscript.Quit
End If

vDirName = Wscript.Arguments(0)
vDirPath = Wscript.Arguments(1)

' Get the name of the current directory
Set fso = WScript.CreateObject( "Scripting.FileSystemObject" )
vDirPath = fso.GetFolder( vDirPath ).Path

' Does this IIS application already exist in the metabase?
On Error Resume Next
Set objIIS = GetObject( "IIS://localhost/W3SVC/1/Root/" & vDirName )
If Err.Number = 0 Then
result = shell.Popup( "A virtual directory named " & vDirName & " already exists. " & vbCrLf & vbCrLf & "Would you like it re-mapped for this sample?", 0 ,"Remap Virtual Directory?", 4 + 32 )' 4 = YesNo & 32 = Question
If result = 6 Then ' 6 = Yes
DeleteVirtualDirectory vDirName
Else
WScript.Quit
End If
End If

'Using IIS Administration object , turn on script/execute permissions and define the virtual directory as an 'in-process application.
Set objIIS = GetObject( "IIS://localhost/W3SVC/1/Root" )
Set vDirObj = objIIS.Create( "IISWebVirtualDir", vDirName )

vDirObj.Path = vDirPath
vDirObj.AuthNTLM = True
vDirObj.AccessRead = True
vDirObj.AccessWrite = True
vDirObj.AccessScript = True
vDirObj.AccessExecute = True
vDirObj.AuthAnonymous = True
'vDirObj.AnonymousUserName = owner
vDirObj.AnonymousPasswordSync = True
vDirObj.AppCreate True
vDirObj.SetInfo

If Err.Number > 0 Then
shell.Popup Err.Description, 0, "Error", 16 ' 16 = Stop
WScript.Quit
End If

' Get the name of the account for the anonymous user in IIS
owner = vDirObj.AnonymousUserName

' Change necessary folder permissions using CACLS.exe
aclCmd = "cmd /c echo y| CACLS "
aclCmd = aclCmd & """" & vDirPath & """"
aclCmd = aclCmd & " /E /G " & owner & ":C"
rtc = shell.Run( aclCmd , 0, True )

aclCmd = "cmd /c echo y| CACLS "
aclCmd = aclCmd & """" & vDirPath & """"
aclCmd = aclCmd & " /E /G ""VS Developers"":C"
rtc = shell.Run( aclCmd , 0, True )

If Err.Number > 0 Then
shell.Popup Err.Description, 0, "Error", 16 ' 16 = Stop
WScript.Quit
Else
res = vDirName & " has been created at" & vbCrLf & vDirPath
shell.Popup res, 0, "All done", 64 ' 64 = Information
End If

Sub DeleteVirtualDirectory( NameOfVdir )

Set iis = GetObject("IIS://localhost/W3SVC/1/Root")
iis.Delete "IISWebVirtualDir", vDirName

If Err.Number <> 0 Then

errorString = "Unable to delete exisiting virtual directory."

If Err.Description Is Nothing Then
errorString = errorString & "Error Code: " & Err.Number
Else
errorString = errorString & "Description: " & Err.Description
End If

shell.Popup errorString, 0, "Error", 16 ' 16 = Stop
End If

End Sub
2004-11-05 16:55:00 | [匿名用户:leighsword]
对不起,目前本随笔不允许发表新评论.

Powered by: Joycode.MVC引擎 0.5.1.8