“Cannot add duplicate collection entry of type…” error in IIS 7/7.5

9 02 2012

I came across an “HTTP Error 500.19 – Internal Server Error” error when trying to access a static page on IIS 7 running on Windows 2008 Server.  So, here’s what I did that fixed the issue:

1. Checked the event logs first and saw this:

image

2. Checked out the ISAPI Filters of the “Default Web Site” as stated in the event log and look what came up:

image

3. Next, checked “c:\Windows\System32\inetsrv\config\applicationHost.config” and voila, saw two entries for “ASP.Net_2.0_for_V1.1”:

Line 312:

<isapiFilters>
            <filter name="ASP.Net_2.0.50727.0" path="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_filter.dll" enableCache="true" preCondition="bitness32,runtimeVersionv2.0" />
            <filter name="ASP.Net_2.0_for_V1.1" path="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_filter.dll" enableCache="true" preCondition="runtimeVersionv1.1" />
            <filter name="ASP.Net_4.0_64bit" path="c:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_filter.dll" enableCache="true" preCondition="runtimeVersionv4.0,bitness64" />
            <filter name="ASP.Net_4.0_32bit" path="c:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_filter.dll" enableCache="true" preCondition="runtimeVersionv4.0,bitness32" />
        </isapiFilters>

Line 960:

<location path="Default Web Site">
<system.webServer>
<isapiFilters>
<filter name="ASP.Net_2.0_for_V1.1" path="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_filter.dll" />
</isapiFilters>
</system.webServer>

After removing the second <filter name…> in line 960 (like so below), and restarting IIS, everything worked as expected. 

<location path="Default Web Site">
<system.webServer>
<isapiFilters>
</isapiFilters>
</system.webServer>

Hope this helps someone out there.



PowerShell Pack

9 02 2012

In case you didn’t know, PowerShell has a pack that has offers add-on goodies.  Get it at:

http://archive.msdn.microsoft.com/PowerShellPack/Release/ProjectReleases.aspx?ReleaseId=3341



Visual Studio 2010 access denied on “Publish”

8 02 2012

I was getting the errors below when publishing to a file system:

Connecting to C:\inetpub\wwwroot\webapp
Transformed Web.config using Web.Debug.config into obj\Debug\TransformWebConfig\transformed\Web.config.
Copying all files to temporary location below for package/publish:
obj\Debug\Package\PackageTmp.
Publishing folder /…
Unable to add ‘Web.config’ to the Web site.  Unable to add file ‘Web.config’.  Access is denied.
Publishing folder Account…
Publishing folder bin…
Unable to add ‘bin/webapp.dll’ to the Web site.  Unable to add file ‘bin\webapp.dll’.  Access is denied.
Unable to add ‘bin/webapp.pdb’ to the Web site.  Unable to add file ‘bin\webapp.pdb’.  Access is denied.
Publishing folder Scripts…
Publishing folder Styles…
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========

The fix: Open Visual Studio 2010 with “Run as Adminstrator” (right-click it and choose that option).



PowerShell: Extracting certain lines in any file

28 10 2011

I had quite a large file that I needed to parse, and the challenge was to extract certain lines that didn’t match a certain condition.  The solution . . . PowerShell, like so:

select-string -path filename -notmatch "criteria" | foreach {$_.line} | out-file -filepath filename -encoding ascii

That’s it!



PowerShell: Deleting entire lines in a text file based on a partial string match

11 07 2011

PS C:\workspace> (gc “fileToParse.txt”) -notmatch "<criteria>" | out-file
"resultFile.txt"

Note: <Criteria>, for example, “not".