I'm writing an implementation plan involving changing ASP.NET machine key settings for .NET 4.0 on servers that are running IIS 7.0.

I'd prefer to have the setting changed via IIS Manager.

On my local machine, running IIS 7.5 this is easy. Go into IIS Manager, and in the Actions pane on the right hand right is a command Change .NET Framework Version. I can change this between .NET 2.0 and .NET 4.0, and this changes which machine level web.config I am editing when I change the machine key from the IIS Manager home page.

However IIS 7.0 does not have the Change .NET Framework Version command anywhere I can see. I therefore can't see any way for the .NET 4.0 machine key setting to be changed, other than manually editing C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config

So two questions

  1. Is there an equivalent to the IIS Manager 7.5 command "Change .NET Framework Version" in IIS Manager 7.0?
  2. Is there any other way to set the machine key settings in C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config without manually editing the file on an IIS 7.0 machine?

It should be possible to script such a process, I would probably start with PSH as it has inbuilt XML support and access to .NET (useful for generating new keys if they are being specified).

But the first thing is to get the list of virtual directories at which to start. This is mostly easily done with appcmd:

# Use array constructor to force an array, event with only one result
# format: VDIR "name" (physicalPath:path)
$vdirs = @(C:\Windows\system32\inetsrv\appcmd.exe list vdir)
$vdirs = $vdirs | Where-Object { -not [string]::IsNullOrEmpty($_) } | Foreach-Object -Process {
  if ($_ -match "physicalPath:([^)]+)\)$") {

At this point $vdirs is an array of folders mapped to IIS.

Within each of these search for web.config files:

$configFiles = $vdirs | Foreach-Object -Process {
  Get-ChildItem -Path $_ -Recurse -Filter "web.config" | Foreach-Object -Process { $_.FullName }

Which is an array of the full path names of the web.config files. At this point you can use PowerShell's XML support to examine or update any part of the file you like

  • 1
    Hmm, looking at this again it doesn't really answer the question - the question wasn't modifying web.config in virtual directories, it was modifying the machine level config. – SamStephens Apr 5 '13 at 20:18

Looks like you need this hotfix to make the "Change .NET Framework Version" show up in IIS Manager 7.0


I'm still keen to know if there are any other ways to set the MachineKey without editing the web.config manually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.