IIS 6.0 DirectoryEntry ScriptMaps property and set .Net version

After building the website, I notice that it is setting the asp.net version to 1.1. I would like to change this to version 2.0.50727 in the code. I found that the ScriptMaps property has a string list of all file extensions and code mappings. But I didn't figure out how to change all the .net related values? Or is there a way to tell him to use a different version with .invoke?

+2


source to share


3 answers


DirectoryEntry sited = new DirectoryEntry(string.Format("IIS://localhost/w3svc/{0}/Root", websiteID.ToString()));
sited.Properties["AccessRead"].Add(true);

PropertyValueCollection testScriptMap = sited.Properties["ScriptMaps"];

object[] allValues = (object[])testScriptMap.Value;
object[] newValues = new object[allValues.Length];
string oldVersion = "v1.1.4322";
string newVersion = "v2.0.50727";
for (int i = 0; i < allValues.Length; i++)
{
    if (allValues[i] is string)
    {
        string temp = allValues[i] as string;
        if (temp.Contains(oldVersion))
        {
            newValues[i] = temp.Replace(oldVersion, newVersion);
        }
        else
        {
            newValues[i] = allValues[i];
        }
    }
    else
    {
        newValues[i] = allValues[i];
    }
}
testScriptMap.Value = newValues;            

sited.CommitChanges();

      



After a little trial and error, I found a solution. I took all the objects in the generated site and made a copy where I changed the version part of the path string. Then I set the value property of the scriptMaps object to point to the new updated array of objects.

+5


source


One easy way is to execute " aspnet_regiis -i

". The file aspnet_regiis.exe

will be located at - C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe

.

Alternatively, you can take the hard path and take a look at the article on Modifying IIS Metabase .



Taking the harder path is much cooler for me than the easy one!

+1


source


The following command installs the version of ASP.NET associated with the tool and updates the script maps of all existing ASP.NET applications. Note that only applications that are currently mapped to an earlier version of ASP.NET are affected.

Aspnet_regiis -i

Aspnet_regiis.exe is located in the following path:

C: \ WINDOWS \ Microsoft.NET \ Framework \ "dot net version you want to change to"

in your case will be under v2.0.50727:

C: \ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727

source: ASP.NET IIS Registration Tool

0


source







All Articles