'System.Web.Extensions' trouble deploying .Net Framework 4 Website on IIS7 - asp.net

I am trying to deploy a .Net framework 4 website on IIS7 server. I have already changed the application-pool's target framework to .Net 4, but the app is still showing me the error:
"The configuration section 'system.web.extensions' cannot be read because it is missing a section declaration"
I am guessing that has something to do with the new feature of .Net4 that lets me have a compact Web config file. I think for some reason IIS7 is not happy with this.
What can I do to deploy this app successfully or do I have to scale back to v3.5? I am sure there is a solution out there.
Do you have any suggestions?

You can also get this very same error if you create a new website in IIS 7(.5) as the application pool it creates for the new site may still be set to 2.0, and as such, system.web.extensions is not valid in a 2.0 configuration file.
Simply go into IIS Manager, choose the application pools, select the one for your app, right-click, Advanced Settings and set .NET framework version to v4.

Module IIS Web Core
Notification BeginRequest
Handler Not yet determined
Error Code 0x80070032
Config Error The configuration section 'system.web.extensions' cannot be read because it is missing a section declaration
Config File \\web.config
The error is due to this system.web.extensions section added to the Web.config
<system.web.extensions>
<scripting>
<webServices>
<!-- Uncomment this line to customize maxJsonLength and add a custom converter
<jsonSerialization maxJsonLength="1024000">
-->
</webServices>
<scriptResourceHandler enableCompression="true" enableCaching="true"/>
</scripting>
</system.web.extensions>
For some reason adding that section, overrides the system.web.extensions group. The solution is to
Comment the code above if you don't need it.
Add the code below to the Web.config section group
..
<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>

I could solve this issue myself after some hunting around (happens!).
apparently has nothing to do with the way the config file is structured, it is the assembly for ASP.Net Ajax which is not deployed on my target server but might be present on my dev machine.
I deleted the entry from the web.config file and this issue was resolved, there were some other minor issues but nothing worth mentioning.
The deployment experience for IIS7+.Net Framework 4 wasn't too difficult and the added capabilities will going to be worth it.

I found the answer from Leo Tang post:
This issue not caused by the web.config migration. If you update you application to .Net Framework4.0, but assign this application to an application pool running under .Net Framework3.5 or previous version, you will encounter this error.
You can assign this application to an .Net Framework4.0 application pool in IIS to fix issue.
So, if you read the error The configuration section 'system.web.extensions' cannot be read because it is missing a section declaration it’s because the application you have deployed is running under an application pool configured to run under .NET 2.0 or 3.5 (DefaultAppPool? DefaultAppPool by default is set to .NET 2.0).
Perform the following steps:
Run IIS (exec 'inetmgr')
Select your application (probably 'Server\Sites\Default web site\Your application name' from the tree on the left panel)
Open your application settings (click 'Basic Settings' from 'Actions' the right panel) and look at the Application Pool.
Now choose the action that best fits your needs:
You can change the application pool for your application (button select in 'Application Edit' form, then choose 'ASP.NET v4-0 Classic'). This change will effect just this application
OR you can edit the application pool (probably Server\Application pools\DefaultAppPool rom the tree on the left) and set it to run under .NET Framevork v4.0 . Be careful: this change will effect every application under this Application Pool... is this what you want? maybe...

If "aspnet_regiis.exe -iru" don't help and you sure, that you try to launch site under .NET 4.0 App pool, it may be the problem in configuration inheritance of IIS 7.0. Web server reads machine.config of .NET 2.0.
Applying of hotfix KB958854 would solve the problem with configuration inheritance. I have successfully fixed my problem in this way.

It’s because you’ve deployed your application on to an IIS Server where the application’s AppPool is set to run under the DefaultAppPool. DefaultAppPool is automatically configured to run under .NET 2.0 rather than .NET 4.0. This means that the System.Web.Extensions stuff is unavailable to that version of the .NET Framework.
To change the Application Pool (AppPool) settings for your web application
1. Select the application directory
2. Under Actions, click Basic Settings…
3. Change the Application Pool to ASP.NET v4.0 (or another .NET 4.0 app pool) by clicking on the Select… button.
4. Click OK
Re-run your application and it should work.
Check this link for graphical demonstration.

I solved the issue by following below steps:
1. set application pool framework to 4.0
2. if point 1 wont work, then problem could be related to config inheritance.
Apply hotfix from http://support.microsoft.com/kb/958854
This should solve the issue.

Related

ChartImg.axd error in ASP.NET 3.5.2

I am developing a webapp in ASP.NET framework 3.5.2.
After draging the Chart Control from the toolbox to where I want it in my .aspx page, there seems to be this added at the top of the document:
<%# Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
When I run I get the error: "Error executing child request for ChartImg.axd."
I have tried adding the following into system.web in my Web.config
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
</httpHandlers>
Then I get:
HTTP Error 500.23 - Internal Server Error
An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.
Most likely causes:
•This application defines configuration in the system.web/httpHandlers section.
It says that I can try to "Migrate the configuration to the system.webServer/handlers section".
How do I do this and how till it affect my webapp? Will something else stop working and is it possible to revert the migration?
With ASP.NET 3.5 projects where I got this error I went into IIS and changed the APplication Pool to run in Classic Managed Pipeline Mode rather than Integrated
To change this go to :IIS, go to Application Pools, Find the pool you're using and change it to Classic.

web.config - Invalid configuration data for the page?

Created a Web Application in ASP.NET (c# language), than Build -> Published to Desktop, moved all files and folders to the ./test directory of the root of my localhost, than go to localhost/test/Default.aspx, and get this error message:
HTTP Error 500.19 - Internal Server Error The requested page cannot be
accessed because the related configuration data for the page is
invalid.
Points to this bit of code within web.config:
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
Actually, more digging reveals this:
There is a duplicate
'system.web.extensions/scripting/scriptResourceHandler' section
defined
Can I just define this in the root web.config file? Or is it safe to remove it altogether?
If this entry is defined in machine.config, then it's considered duplicate. Either remove this entry from web.config or add a remove sentence before.
<remove name="scriptResourceHandler/>

MVC 3 project rejects requests for Razor views with CS0103: The name 'model' does not exist

I have and MVC3 project that once upon a time was an MVC2 project. I've been developing it using IIS express to test.
Now I deployed it to IIS proper on my machine, jiggled some web.config settings, and messed around for an hour getting the razor build provider to be registered, which must not be done right because the new project template doesn't include a line adding that build provider in the web.config.
At any rate, any time I go to a strongly-typed Razor view I get this:
Compiler Error Message: CS0103: The name 'model' does not exist in the current context
Source Error:
Line 1: #model Cairn.Cartography.Features.Peak
Any thoughts on what is going on, and how I might fix it without firebombing this box and looking around for my windows install cd? :)
I was missing:
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
in this part of my web.config file:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="Cairn"/>
<add namespace="Cairn.UI.Web"/>
<add namespace="Cairn.UI.Web.Helpers"/>
</namespaces>
</pages>
</system.web.webPages.razor>
I haven't the foggiest what this means or why it matters, or why it is absent from the web.config generated for a brand new project, but it works.
? Oh well
yes.. reinstall asp.net MVC3 again
either get the MSI file from here: http://go.microsoft.com/fwlink/?LinkID=208140
or use Web Platform Installer from here: http://www.microsoft.com/web/gallery/install.aspx?appid=MVC3

Could not load type 'System.ServiceModel.Activation.HttpHandler' Version conflict with WCF REST

I've run into a problem with WCF REST Service. I get:
Could not load type 'System.ServiceModel.Activation.HttpHandler' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
when running inside of the IIS in an ASP.NET 4.0 AppPool.
The problem seems to occur only if:
Running inside of IIS
When ASP.NET Comaptibility is enabled
Running in Cassini - no problem it works properly. Running with ASP.NET compatibility off - no problem it works.
It appears that it's some sort of handler version conflict trying to instantiate the wrong version of the handler that in turn tries to load an older version of System.ServiceModel, but I haven't been able to trace this down.
Anybody seen anything like this before and have any ideas how to track this down further?
I've looked in ApplicationHost.config and the master web.config files for System.ServiceModel and HttpHandler references but no luck. There.
+++ Rick ---
fire up your Visual Studio 2010 Command Prompt or browse to "C:\Windows\Microsoft.NET\Framework\ v4.0.30319". And run the following command from the command prompt:
aspnet_regiis.exe -iru
This will register latest .net version. Also make sure your app pool is running latest version of .net
So as expected this turned out to be a versioning conflict in the default handler mappings in ApplicationHost.config. Specifically IIS has mappings for ASP.NET 2.0 and ASP.NET 4.0 specific references to the service activation handler (and module) and the 2.0 references weren't restricted by a version specific preCondition.
To fix the above problem I had to change (at the System root in ApplicationHost.config):
<add name="svc-Integrated" path="*.svc" verb="*"
type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
preCondition="integratedMode" />
to:
<add name="svc-Integrated" path="*.svc" verb="*"
type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
preCondition="integratedMode,runtimeVersionv2.0" />
Note the EXPLICIT runtimeVersion2.0. There are additional *.svc maps in the same section for the runtimeVersion4.0 which then fire the appropriate runtimes.
According to Microsoft this situation can arise when some older tools (I'm guessing Azure tools???) are installed that don't register the runtime version properly.
Problem solved.
There is one more way if all of above doesn't work. (Strange)
We were using Windows Server 2008 R2 SP1 with IIS 7.5.7600
After registering latest framework as given in above answer,
You need to the add handler mapping to v.4.0 assembly manually to web.config and remove "ServiceModel" from Modules.
<system.webServer>
<handlers>
<remove name="svc-Integrated" />
<add name=".svc" verb="*" path="*.svc" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory,
System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
<modules>
<remove name="ServiceModel" />
</modules>
</system.webServer>
More here

visual studio 2k8 (and 2k10) cannot compile web application when gac assemblies are moved into global web.config

I have numerous ASP.NET 3.5 web applications with verbose application-level web.config files which I wish to slim down and make more readable.
Visual Studio 2010 has just arrived and has already started "cleaning up" various sections of the web.config - so now is a perfect time for me to continue the good work and do the same in other areas of the web.config file.
Currently I have several third party assemblies all happily registered in the GAC, these are then referenced in each application-level Web.Config see below;
<configuration>
<system.web>
<compilation defaultLanguage="C#" debug="true">
<assemblies>
<add assembly="AjaxControlToolkit, Version=3.0.30512.20315, Culture=neutral, PublicKeyToken=28F01B0E84B6D53E"/>
<add assembly="aspNetEmail, Version=3.5.2.0, Culture=neutral, PublicKeyToken=BC571E8DA1C1F543"/>
<add assembly="aspNetDns, Version=3.0.0.0, Culture=neutral, PublicKeyToken=BC571E8DA1C1F543"/>
<add assembly="Microsoft.Practices.EnterpriseLibrary.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
</system.web>
</configuration>
I have moved the above compilation-node into the global web.config file located at Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config - and the application runs just fine under IIS7 i.e. the application has no trouble finding these GAC'd assemblies.
however when I now compile (shift+ctrl+b) my web application in visual studio 2k8 or 2k10 I'm getting the familiar error "The type or namespace name 'aspNetDns' could not be found (are you missing a using directive or an assembly reference?)"
What do I have to do to get visual studio to recognise the whereabouts of these GAC'd libraries? I tried copying them into windows\system32 but no joy there...
help! :)
NB: I have also tried working with the machine.config but still no luck
Solved it.
I needed to edit the global web.config in the x86 directory (as well as the x64 version) - the x86 version is obviously the one Visual Studio was looking at whilst compiling the app, whereas IIS was looking at the x64 version of the global web.config when running the app.
Drag / drop the assemblies to c:\windows\assembly on your local machine where you are recompiling.

Resources