219

On attempting to deploy a .net 3.5 website on the default app pool in IIS7 having the framework section set to 4.0, I get the following error.

There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined.

Commenting off the offending lines didn't help either. Any pointers on what I need to do or look at?

bluish
  • 23,093
  • 23
  • 110
  • 171
user20358
  • 12,976
  • 29
  • 106
  • 174

15 Answers15

353

If your plan is to deploy to an IIS that has an Application Pool running in .net 4.0 you will need to cleanup the web.config that includes all the section Definitions that point to .net 3.5. The reason this fails is because these section definitions are already included in the root web.config in .NET 4.0 (see %windir%\microsoft.net\framework\v4.0.30319\config\machine.config) that include all the system.web.extensions declared already.

Another quick fix is to have the application pool set to 2.0 just as your development machine appears to have,.

Carlos Aguilar Mares
  • 12,951
  • 2
  • 35
  • 35
  • Thanks. I had actually figured this workaround after tinkering around some more.. – user20358 Aug 04 '10 at 06:14
  • 3
    Thank you for explaining this. I kept seeing the solution to remove a section from the config file and I'm wondering, "how is cutting out parts of your config file a solution"? – Adam Bruss Apr 09 '13 at 20:48
  • Thanks! You just helped me fix a semi-urgent production site problem caused by someone/something changing its application pool. – Sam Apr 15 '13 at 01:29
  • 17
    MY APP POOL WAS SET TO 4.0 INSTEAD OF 2.0 ! – RolandoCC Jan 30 '14 at 17:33
  • Since myApp was first deployed, wasn't an App, was a virtual directory. I had to go to the Default Web Site and convert the virtual dir to an Application – apacay Sep 02 '14 at 13:49
  • 1
    That was easy, switch this older site to a 2.0 app pool and viola it works! Thanks! – mgrenier Sep 05 '14 at 14:37
  • 1
    Just removing the .net 3.5 section in the web.config worked for me – Anand Mar 15 '16 at 14:58
  • [Here](https://blogs.msdn.microsoft.com/gaurav/2013/10/01/there-is-a-duplicate-scriptresourcehandler-section-defined/) is a good explanation why this error appears. – elshev Feb 22 '17 at 14:58
  • Backup. Edit `C:\inetpub\wwwroot\THATAPPLICATION\web.config` -> remove whole sectionGroup line that contains Version=3.5.0.0 – Ivan Chau Apr 28 '17 at 12:09
  • I truly hate these IIS things – Daniel Dolz Sep 03 '20 at 14:19
53

The solution for me was to change the .NET framework version in the Application Pools from v4.0 to v2.0 for the Default App Pool:

enter image description here

valiano
  • 10,373
  • 4
  • 36
  • 60
DaveDev
  • 38,095
  • 68
  • 199
  • 359
  • 13
    aaaand, if you're actually using .NET 4.0 in the application? – Michael Paulukonis Dec 05 '12 at 15:40
  • 3
    @MichaelPaulukonis I had this problem, turned out there was a web.config in the root website that my website was inheriting from. – FarFigNewton Mar 26 '13 at 20:39
  • @MichaelPaulukonis, pfft like that'll happen! – DaveDev Aug 28 '15 at 05:23
  • I had this problem when my app was upgraded from 3.5 to 4.0, the app pool was correctly updated, but the web.config was outdated. Web.config was trying to add all those section groups that since 4.0 are native and don't need to be explicitly added. – drizin Feb 17 '17 at 20:40
50

If, like me, you need to target v4 but can only build with .net 3.5, follow the instruction here. Just replace in your web.config the whole content of the <configSections> with:

<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
  <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
    <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
    <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions,  Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>
      <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
      <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
      <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
    </sectionGroup>
  </sectionGroup>
</sectionGroup>

Johann
  • 11,420
  • 10
  • 56
  • 82
3

Set the application pool to 2.0, I did it and worked.

3

Necromancing.
If you don't have any system.web.extensions config-sections or handler/module entries in your web.config, this problem is caused because you/somebody else copied a VisualStudio-Project (2013/2015/2017) while having hidden-files unhidden.

Because of that, it will not only copy .git, but also .VS, which contains an IIS-Express applicationhost.config file, which points to web.config files at paths that don't exist (or worse, paths that do exist, but do not have the same content)...

Solution:
Delete the applicationhost.config file in the .VS folder.
Or just delete the .VS folder altogether.
Visual Studio will re-create it.

Stefan Steiger
  • 68,404
  • 63
  • 337
  • 408
2

My app was an ASP.Net3.5 app (using version 2 of the framework). When ASP.Net3.5 apps got created Visual Studio automatically added scriptResourceHandler to the web.config. Later versions of .Net put this into the machine.config. If you run your ASP.Net 3.5 app using the version 4 app pool (depending on install order this is the default app pool), you will get this error.

When I moved to using the version 2.0 app pool. The error went away. I then had to deal with the error when serving WCF .svc :

HTTP Error 404.17 - Not Found The requested content appears to be script and will not be served by the static file handler

After some investigation, it seems that I needed to register the WCF handler. using the following steps:

  1. open Visual Studio Command Prompt (as administrator)
  2. navigate to "C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation"
  3. Run servicemodelreg -i
1

Apparently, other have (had) this problem. They rebuild in Framework 4.0. Can you?

Also, see this about making sure your IIS is fresh.

Tobiasopdenbrouw
  • 12,649
  • 1
  • 19
  • 27
1

In my case it happened after I converted the whole solution (using an extension called Target Framework Migrator) to 4.6.2 but ended up undoing the changes and going back to 3.5 (solution is versioned by TFS). To solve this, I converted just the problematic project (which was using IIS Express to run) to 4.6.2 and then back to 3.5.

l0cke
  • 486
  • 1
  • 8
  • 16
  • thanks. it seems that reverting back and undoing changes will not correctly bring the app to .NET 3.5 state correctly. – Iman Aug 04 '18 at 05:49
0

Another way to avoid this problem that may help others is build your .net web service to version 4.0 or higher if possible.

Aelphaeis
  • 2,495
  • 3
  • 21
  • 41
0

In my case I wanted to manually add urlrewrite rule and couldn't see the obvious error (I missed <rules> tag):

wrong code:

    <rewrite>
      <rule name="some rule" stopProcessing="true">
        <match url="some-pattenr/(.*)" />        
        <action type="Redirect" url="/some-ne-pattenr/{R:1}" />
      </rule>
    </rewrite>    

  </system.webServer>
</configuration>

proper code (with rules tag):

    <rewrite>
      <rules>
        <rule name="some rule" stopProcessing="true">
          <match url="some-pattenr/(.*)" />        
          <action type="Redirect" url="/some-ne-pattenr/{R:1}" />
        </rule>
      </rules>
    </rewrite>

  </system.webServer>
</configuration>
Mariusz Pawelski
  • 18,550
  • 7
  • 54
  • 71
0

In my case I had 2 different apps sharing the same app pool. The first one was using the .net4.5 framwork and the new one was using 2.0. When I changed the second app to it's own app pool it starting working fine with no changes to the web.config.

Dowlers
  • 1,256
  • 16
  • 26
0

My resolution was kind of stupid.

  • I installed a copy of .net 3.5

  • Created another app pool and selected .net 3.5 (it says 2.0.5077 in the drop down)

  • Added my website to that app pool

  • Recycled the old and new pools and the site started working.

It came down to me not having 3.5 installed even though the turn on windows features said I did and creating another app pool to use. I hope this helps others.

TheGhoul
  • 1
  • 1
0

I've solved it, doing the following steps:

  1. I created a new application's group in IIS.
  2. Open advanced settings for the site or web application that is having this problem.
  3. And set the new application's group.

Here you have the images of these steps:

Create a new application's group

After you create the application's group

Set the application group in your site or web app

Giovanny Farto M.
  • 1,339
  • 16
  • 19
0

This error message seems to come up in various situations.

In my case, on top of my application's Web.Config file I had an extra Web.Config file in the root folder (C:\Inetpub\www.root). Probably left there after some testing, I had forgotten all about it, and couldn't figure out what the problem was.

Removing it solved the problem for me.

nassosk
  • 11
  • 3
0

This is maybe the wrong answer for you. But this was the first hit on Google when I tried to solve my problem. With that said...

The same error message occurred for me as well, but when I tried to run IIS Express through Visual Studio.

My problem was that I mistakenly commited my applicationhost.config to TFS. Later when I tried to run the project on my laptop after getting the latest commits. that's when the error occurred.

I found that the virtual directory path was wrong.

<virtualDirectory path="/" physicalPath="C:\Users\user1\Documents\Visual Studio 2015\Projects\ProjectName\ProjectName\ProjectName.Web" />

Hope that this help somebody!

This is my first post, so be gentle :)

MrFile
  • 37
  • 6