Errors installing ASP.NET 4.0

Here is a little problem you might run into when trying to use aspnet_regiis.exe to register ASP.NET 4 on a site.

C:WindowsMicrosoft.NETFrameworkv4.0.30319>aspnet_regiis -i
Start installing ASP.NET (4.0.30319).
.......
Finished installing ASP.NET (4.0.30319).
Setup has detected some errors during the operation. For details, please read the setup log file C:UsersjohnAppDataLocalTempASPNETSetup_00003.log

C:WindowsMicrosoft.NETFrameworkv4.0.30319>

When you look into the mentioned log file and search for “fail” you find this:

2010-09-06 14:27:18 Failure Changing IIS ApplicationHost.config: IIS7Register failed with HRESULT 800700b7: 'Cannot create a file when that file already exists. '

So what’s that all about?

Turns out it is actually down to the fact that aspnet_regiis.exe does not cope too well with the generally accepted environment variable that expands to the Windows directory. So when you look in your applicationHost.config file (in windowssystem32inetsrvconfig) you may find something like this:

<isapiCgiRestriction>
             <add path="%windir%system32inetsrvasp.dll" allowed="true" groupId="ASP" description="Active Server Pages" />
             <add path="%windir%Microsoft.NETFramework64v2.0.50727aspnet_isapi.dll" allowed="true" groupId="ASP.NET v2.0.50727" description="ASP.NET v2.0.50727" />
             <add path="%windir%Microsoft.NETFrameworkv2.0.50727aspnet_isapi.dll" allowed="true" groupId="ASP.NET v2.0.50727" description="ASP.NET v2.0.50727" /> 
             <add path="%windir%Microsoft.NETFrameworkv4.0.30319aspnet_isapi.dll" allowed="true" groupId="ASP.NET v4.0.30319 (32-bit)" description="ASP.NET v4.0.30319 (32-bit)" />
             <add path="%windir%Microsoft.NETFramework64v4.0.30319aspnet_isapi.dll" allowed="true" groupId="ASP.NET v4.0.30319 (32-bit)" description="ASP.NET v4.0.30319 (32-bit)" />
             <add path="%windir%system32inetsrvwebdav.dll" allowed="true" groupId="WEBDAV" description="WebDAV" />
</isapiCgiRestriction>

If you change the highlighted bits to the appropriate hard coded location (e.g. c:windows ) and try again you should find it works.

HTH

Doug