Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?
share|improve this question

2 Answers 2

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:([^)]+)\)$") {
   $matches[1]
  }
}

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

share|improve this answer
    
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
up vote 0 down vote accepted

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

http://support.microsoft.com/kb/958854

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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