如何设置创建IIS虚拟目录时使用的.NET Framework版本?

时间:2009-03-24 16:20:23

标签: c# .net iis installer

我有一个创建虚拟目录的方法。在创建虚拟目录时,如何将.NET Framework设置为版本2?

到目前为止,我的方法看起来像这样:

private static void CreateVDir(string metabasePath, string vDirName, string physicalPath)
{
    //  metabasePath is of the form "IIS://<servername>/<service>/<siteID>/Root[/<vdir>]"
    //    for example "IIS://localhost/W3SVC/1/Root".
    //  vDirName is of the form "<name>", for example, "MyNewVDir".
    //  physicalPath is of the form "<drive>:\<path>", for example, "C:\Inetpub\Wwwroot".
    Console.WriteLine("\nCreating virtual directory {0}/{1}, mapping the Root application to {2}:",
                      metabasePath, vDirName, physicalPath);

    DirectoryEntry site = new DirectoryEntry(metabasePath);
    string className = site.SchemaClassName;
    if ((className.EndsWith("Server")) || (className.EndsWith("VirtualDir")))
    {
        DirectoryEntries vdirs = site.Children;
        DirectoryEntry newVDir = vdirs.Add(vDirName, (className.Replace("Service", "VirtualDir")));
        newVDir.Properties["Path"][0] = physicalPath;
        newVDir.Properties["AccessScript"][0] = true;
        // These properties are necessary for an application to be created.
        newVDir.Properties["AppFriendlyName"][0] = vDirName;
        newVDir.Properties["AppIsolated"][0] = "1";
        newVDir.Properties["AppRoot"][0] = 
           "/LM" +
           metabasePath.Substring(metabasePath.IndexOf("/", ("IIS://".Length)));
        newVDir.CommitChanges();
        Console.WriteLine(" Done.");
    }
    else
        Console.WriteLine(
            " Failed. A virtual directory can only be created in a site or virtual directory node.");
}

2 个答案:

答案 0 :(得分:2)

“ScriptMaps”属性是存储配置映射的位置。也就是说,您可以将* .aspx文件映射到ASP.NET进行处理。一个例子是 Creating ISAPI Mappings Programmatically

答案 1 :(得分:0)

创建虚拟目录后,可以从您选择的.NET框架目录运行aspnet_regiis -s。

在我的系统上,命令看起来像这样:

C:\ Windows \ Microsoft.NET \ Framework64 \ v2.0.50727 \ aspnet_regiis -s W3SVC / 1 / ROOT / SampleApp1

我已成功完成安装程序中的自定义操作。