简体   繁体   中英

IIS 6.0 DirectoryEntry ScriptMaps property and set .Net version

After creating a web site, i notice that it sets the asp.net version to 1.1. I would like to in code change this to version 2.0.50727. I found that in the ScriptMaps property there are string list of all the file extensions and code mapping. But I have not figured out how to change all of the values that are connected to .net? Or is there a way to tell it to use an other verison with .invoke?

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 little trial and error I found a solution. I took all the objects in the created 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 object array.

One easy way is to execute " aspnet_regiis -i ". The aspnet_regiis.exe file will be located at - C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\aspnet_regiis.exe .

Alternately, you can take the hard way, and take a look at an article on modification of IIS Metabase .

Taking the harder way, to me, is much cooler than the easy one!

The following command installs the ASP.NET version 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

the Aspnet_regiis.exe is under 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM