Grzenio
Grzenio

Reputation: 36639

How can I set the version of .NET Framework used while creating an IIS vitual directory?

I have a method that creates a virtual directory. How can I set the .NET Framework to version 2 while I create the virtual directory?

My method looks like this so far:

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.");
}

Upvotes: 1

Views: 777

Answers (2)

David
David

Reputation: 34543

The "ScriptMaps" property is where the configuration mappings get stored. That is, that's where you can map *.aspx files to get processed by ASP.NET. An example is in Creating ISAPI Mappings Programmatically.

Upvotes: 2

jlew
jlew

Reputation: 10591

After you have created the virtual directory, you can run aspnet_regiis -s from the .NET framework directory of your choice.

On my sytem, the command would look something like this:

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

I have done this from a custom action in my installer successfully.

Upvotes: 0

Related Questions