using System.DirectoryServices
// .....
/// <summary>
/// 创建iis虚拟目录
/// </summary>
/// <param name="physicalPath">虚拟目录所指向的物理路径</param>
/// <param name="virtualDirName">虚拟目录名称</param>
private void CreateDirectory(string physicalPath, string virtualDirName)
{
if (!DirectoryEntry.Exists("IIS://localhost/W3SVC/1/ROOT" + "\\" + virtualDirName))
{
try
{
DirectoryEntry root = new DirectoryEntry(IISWebSiteRoot)
DirectoryEntry tbEntry = root.Children.Add(virtualDirName, root.SchemaClassName)
tbEntry.Properties["Path"][0] = physicalPath //设置虚拟目录指向的物理路径
tbEntry.Invoke("AppCreate", true)
tbEntry.Properties["AccessRead"][0] = true//设置读取权限
// tbEntry.Properties["AccessRead"][0] = false
tbEntry.Properties["ContentIndexed"][0] = true
tbEntry.Properties["DefaultDoc"][0] = "Index.aspx,Default.aspx" //设置默认文档,多值情况下中间用逗号分割
tbEntry.Properties["AppFriendlyName"][0] = virtualDirName //应用程序名称
tbEntry.Properties["AccessScript"][0] = true//执行权限
tbEntry.Properties["DontLog"][0] = true
tbEntry.Properties["AuthFlags"][0] = 0 //设置目录的安全性,0表示不允许匿名访问,1为允许,3为基本身份验证,7为windows继承身份验证
tbEntry.Properties["AuthFlags"][0] = 1
tbEntry.CommitChanges()
}
catch (Exception ex)
{
Respone.write("<script>alert('" + ex.Message + '')<script>')
}
}
}
1、打开IIS管理器。
2、点击web服务扩展
3、找到Active Server Pages 单击鼠标右键,选择“允许”
这样设置过后你的IIS就支持asp了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)