CrystalImageHandler.aspx not found - asp.net-mvc

I am using Crystal reports viewer on a normal ASP.NET aspx page in an MVC3 application. In a controller action I am simply redirecting to the aspx page and the report shows fine. But the problem is with dynamic images. I have found the simplest solution for this and this to pass the image path as a report parameter and set this parameter as image source. In Visual Studio preview this works fine but when executing I see this error on the page.
"NetworkError: 404 Not Found -
server/ReportWebForms/CrystalImageHandler.aspx?dynamicimage=cr_tmp_image_4fbcb73a-e001-4365-84fc-164788dd1605.png"
So I assume, having no previous experience with crystal reports, that the problem is in CrystalImageHandler.aspx.
I have these entries in the Web.config:
<httpHandlers><add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/></httpHandlers></system.web>
<handlers><add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode"/></handlers></system.webServer>
Is this an MVC type of a problem? Can anyone help with this please?
THank you

I had the same problem, but fortunately I have some experience with Crystal Reports.
You just need to change the Web.config, because the "path" attribute is set to site root.
It will work if you open the url in browser and remove the ReportWebForms from it.
Actually I've just added 2 more lines of configuration:
<system.web>
<httpHandlers>
<add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
<!-- Added -->
<add verb="GET" path="Reports/CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
<add verb="GET,HEAD" path="asset.axd" validate="false" type="Telerik.Web.Mvc.WebAssetHttpHandler, Telerik.Web.Mvc" />
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
<add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode" />
<!-- Added -->
<add name="CrystalImageHandler.aspx_GETR" verb="GET" path="Reports/CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode" />
<remove name="asset" />
<add name="asset" preCondition="integratedMode" verb="GET,HEAD" path="asset.axd" type="Telerik.Web.Mvc.WebAssetHttpHandler, Telerik.Web.Mvc" />
</handlers>
</system.webServer>
And finally you have to add an ignore rule the route for MVC application:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
// Here is added new ignore rule
routes.IgnoreRoute("Reports/{resource}.aspx/{*pathInfo}");
In my case I have a folder named Reports where the .aspx file is placed. I guess you should change this to ReportWebForms in your case.

In my case I only had to ignore MVC's routing.To add onto #Hovhannes solution.You should add this rule to Routeconfig.cs
routes.IgnoreRoute("{*allaspx}", new { allaspx = #".*(CrystalImageHandler).*" });

Use this code as CrystalImageHandler.aspx:
<%# Page Language="C#" AutoEventWireup="true" %>
<script runat="server" language="c#" >
protected void Page_Load(object sender, EventArgs e)
{
CrystalDecisions.Web.CrystalImageHandler handler = new CrystalDecisions.Web.CrystalImageHandler();
handler.ProcessRequest(this.Context);
}
</script>

Answers:
Add this in RouteConfig.cs file
routes.IgnoreRoute("Reports/{resource}.aspx/{*pathInfo}");
Note : "Reports" is the directory name which contains crystal reports viewing aspx page

Related

How to call .cshtml file directly with .cshtml extension from browser without using MVC

I'm getting the below error when i used to call the .cshtml page in IIS 8
Server Error in '/' Application.
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /_header.cshtml
To serve CSHTML files to direct browser requests, you need set following appsetting in web.config to true. By default this value is set to false in web.config.
<add key="webpages:Enabled" value="true" />
For more informat about this setting, Read this resource.
Web.config inside my Views Folder is -
<configuration>
<!--<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>-->
<!--<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="WebApplication1" />
</namespaces>
</pages>
</system.web.webPages.razor>-->
<appSettings>
<add key="webpages:Enabled" value="true" />
</appSettings>
<system.webServer>
<handlers>
<!--<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />-->
</handlers>
</system.webServer>
</configuration>
With this config, I was able to get the CSHTML hit the browser and contents get displayed.
I wouldn't suggest you to do the above settings as by passing RAZOR view Engine for views is not advisable. Instead put all the static files in a folder and add those exceptions to the http pipeline.
To use a cshtml page without MVC you have to use what Microsoft calls "ASP.NET Web Pages." It is another technology inside ASP.NET like Web Forms and MVC. You should be able to enable it by adding this to your web.config.
<appSettings>
<add key="webpages:Enabled" value="true" />
</appSettings>
In the Views folder of your application you will find a web.config. In that web.config you will find the following entry.
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
Basically that entry says that no matter what HTTP verb someone uses it should refuse to return anything that is in the Views folder or a subfolder.
You could remove that entry, but that means someone could request your raw views which could be potentially dangerous.
If you don't want to run the view through Razor then you should create a plain HTML file. You can either put that HTML file in a different folder in your application or you can change the BlockViewHandler to be more specific.
<add name="BlockViewHandler" path="*.cshtml" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />

Razor Compiler Warning/Errors - ASP.NET MVC 4

I have an issue which seems to have been reported here:
Need razor view engine auto-complete to work in a class library?
My issue is the following Warning:
G:\Accountable\Accountable\Views\LedgerUser\EditorTemplates\LedgerServiceViewModel.cshtml:
ASP.NET runtime error: There is no build provider registered for the
extension '.cshtml'. You can register one in the
section in machine.config or web.config.
Make sure is has a BuildProviderAppliesToAttribute attribute which
includes the value 'Web' or 'All'.
This issue is apparent in all my views. Sample images below.
Now all posts and references online that I have found are referencing to adding various Web.config (as mentioned in the previous post) options, but this doesn't seem to work, as I have these configurations defaulted in the project. Here are my Web Configs:
Main Web.config
View root Web Config
I think this issue maybe while im also getting the following compiler errors on the Views:
The name 'Html' does not exist in the current context
What am I doing wrong?
Arrrgghhh i had missed the following from the ROOT Web.config:
<compilation debug="true" targetFramework="4.0">
<!-- New -->
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
This allowed fixed the error and allowed me to use Intellisense within the View.
Putting back the following lines in root Web.config fixed:
<system.web>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
I got it working by simply unloading and reloading the project. All the namespaces above were already there in the root web.config and I was still getting this issue.
Removing the temporary asp.net framework files works for me.
Stop IIS and remove everything under this folder:
C:\Windows\Microsoft.NET\Framework64\[framework version]\Temporary ASP.NET Files
Then restart IIS. Bam!
I tried by restart IIS, removed Temporary ASP.NET Files and changing the compilation tag in the web config file. None of them work for me.
I fixed the issue by removing and adding System.Web.MVC to the project.
In my case Razor syntax are Highlighted in red.

Form data lost during the authentication process-- but only in integrated pipeline mode

I maintain an ASP.NET MVC application (version 1) that currently runs on IIS 7 in classic mode. We'd like to start running the app in integrated pipeline mode instead. However, I am running into a bizarre problem that is preventing us from switching to integrated mode-- when we try, the application stops receiving forms data. (I.e. data send via the POST method.)
By adding a ton of logging to the Global.aspx file, I was able to narrow down the location where the forms data is getting lost. Here's what seems to be happening.
Upon receiving the request, the Application_BeginRequest event is fired. At this point, the forms data is present and can be seen by examining the request object's Forms or Params property. The request's Url property at this point does not have an ".mvc" extension anywhere in it. (More on this below.)
Next, the Application_AuthenticateRequest event is fired. Again, the forms data is present, and the URL has no ".mvc" extension.
At this point, what I would expect to happen is for the Application_PostAuthenticateRequest event to fire. But what acutally happens is that Application_BeginRequest is called again. This time, the forms data is gone-- it's not in Forms, Params, or anywhere else. In addition, the URL has changed so that the controller name part of the Url has an ".mvc" extension tacked onto it. For instance, if the URL in steps 1 and 2 is "/Education/Manage", then in step 3 it shows up as "/Education.mvc/Manage".
The Application_AuthenticateRequest event is fired again. Again, the forms data is missing, and the URL has an ".mvc" extension embedded in it.
This time, Application_PostAuthenticateRequest is fired, and the rest of the page's life cycle proceeds normally. In this and all subsequent events, there's no forms data, and the ".mvc" extension remains present.
The problem only occurs when I switch to the integrated pipeline mode. It works fine in classic mode. I've been googling for days, and unfortunately I've been unable to find any reference to a similar problem. I've also tried editing the Web.config file in several different ways hoping to solve the problem, without any luck. I'm hoping somebody here can shed some light on the issue.
Here are a few relevant code snippets. If there's any other code I should include, please let me know.
From Web.config:
<system.web>
<authentication mode="Forms">
<forms name=".appLive" timeout="60" enableCrossAppRedirects="true" path="/" />
</authentication>
[...]
</system.web>
[....]
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ScriptModule" />
<remove name="UrlRoutingModule" />
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<remove name="FormsAuthenticationModule" />
<remove name="UrlAuthorization" />
<remove name="DefaultAuthentication" />
<add name="DefaultAuthentication" type="System.Web.Security.DefaultAuthenticationModule" />
</modules>
<handlers>
<remove name="AboMapperCustom-17403419" />
<remove name="WebServiceHandlerFactory-Integrated" />
<remove name="ScriptHandlerFactory" />
<remove name="ScriptHandlerFactoryAppServices" />
<remove name="ScriptResource" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="MvcHttpHandler" preCondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add name="AboMapperCustom-17403419" path="*.mvc" verb="GET,POST,HEAD,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,bitness32,runtimeVersionv2.0" responseBufferLimit="0" />
</handlers>
</system.webServer>
From Global.aspx:
public void Application_BeginRequest(Object source, EventArgs e)
{
HttpApplication application = source as HttpApplication;
if (source != null)
{
if (application.Request.AppRelativeCurrentExecutionFilePath.Contains(".mvc"))
{
application.Context.RewritePath(application.Request.Url.PathAndQuery.Replace(".mvc", string.Empty));
}
}
}
Are you by any chance using a URL rewriter or wildcard mapping to support classic mode? You don't need this for integrated mode and should turn it off.

Developing ASP.NET MVC using MonoDevelop on MAC

I am developing a web app using ASP.NET MVC 2.0 in MonoDevelop. I have latest Mono 2.10 and MonoDevelop 2.4.2 and I am running them on Mac.
According to mono’s release notes, it should support ASP.NET MVC 2.0. However, I found MonoDevelop’s project templates still only support ASP.NET MVC 1.0. So I had to create MVC project from MonoDevelop and remove system.web.mvc 1.0.0.0 from reference and add system.web.mvc 2.0.0.0 back in. I can write and compile code OK and MonoDevelop does provide intellisense for methods only exist in MVC 2.0 from both C# and aspx file. However, when I trying to run it from MonoDevelop, I had Compilation error complaining ”<%: Html.LabelFor(model => model.Name) %>” as LabelFor method cannot be recognized .
MonoDevelop uses XSP as its testing web server. I am not sure how it configured as I didn’t install it myself. I think it was installed as part of MonoDevelop. My guess is XSP somehow still uses MVC 1.0 but I can't prove it as I couldn’t even find where it is installed.
Could anyone help me out please?
Update:
I have been suspecting web.config too. Here are how they look like now:
web.config
<configuration>
<system.web>
<compilation defaultLanguage="C#" debug="true">
<assemblies>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</assemblies>
</compilation>
<customErrors mode="RemoteOnly">
</customErrors>
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
<authorization>
<allow users="*" />
</authorization>
web.config under views
<configuration>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler" />
</httpHandlers>
<pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler" />
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
Setting up an ASP.NET project for ASP.NET MVC requires changing and adding a load of settings in web.config. The project template in MD is for ASP.NET MVC 1.0, not ASP.NET MVC 2, so you're probably missing some of the necessary settings, maybe a namespace import.
I have this running with two of my current projects on MacOS X. There were only three steps I needed to make sure were done, they are as follows:
Upgrade the version on all references in both the inner (views) web config and the outter(app) [you've done this].
Dereference System.Web.MVC 1.0.0.0 & Reference 2.0.0.0 for the project
Ensure you don't have 1.0.0.0 binaries in your bin path, the public key does not change
I've done a downloadable zip file of a project template for Asp.Net MVC 4 which builds and runs on/in Mono/Xamarin Studio/MonoDevelop on Mac & Linux at http://www.cafe-encounter.net/p1319/run-asp-net-mvc4-on-mono-monodevelop-on-mac-the-c-template-project.
I should add that a lot of the issue resolution came from Does the Razor View Engine work for Mono?

deploying asp.net mvc app to iis7 .net 4.0 environment, images and css don't load

I am following the steps listed here: http://msdn.microsoft.com/en-us/library/dd483478.aspx at the bottom of that page are steps to manually migrate a web.config from .net 3.5 to 4.0
Currently, the site loads and routes fine, except for static data - images, css..
everything in the migration guide works fine, except : "7.Delete everything between the system.webserver section start and end tags, but leave the tags themselves."
when i do that, I get an error :
"HTTP 500.22 Module ConfigurationValidationModule
Notification BeginRequest
Handler Not yet determined
Error Code 0x80070032 "
my system.webserver looks like this ( i changed 3.5.0.0 references to 4.0.0.0 manually):
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule"/>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="UrlRoutingModule" preCondition="" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory"/>
<remove name="ScriptHandlerFactoryAppServices"/>
<remove name="ScriptResource"/>
<remove name="BlockViewHandler"/>
<remove name="MvcHttpHandler"/>
<remove name="UrlRoutingHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
<add name="MvcHttpHandler" preCondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="UrlRoutingHandler" verb="*" path="UrlRouting.axd" preCondition="integratedMode" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/></handlers>
</system.webServer>
Does anyone know why I can't remove the section, as the guide says to? and why static files won't load? i imagine it's a related issue.
thanks in advance!
EDIT: if i remove the BlockViewHandler line, everything loads fine.
I still am not sure why I can't remove this entire section like the migration guide says, though.
There's more on this error here: AppCmd Migrate Config and HTTP Error 500.22.
You've shown us your <system.webServer> - but do you have anything under <system.web>/<httpModules> or <system.web>/<httpHandlers>? That could be the cause. In IIS7 integrated mode, these sub-sections need to be under <system.webServer> rather than <system.web>.
When you delete everything inside the <system.webServer>, you're deleting this line:
<validation validateIntegratedModeConfiguration="false"/>
which tells IIS not to validate that the configuration works in integrated mode. (This skipping of validation is OK if your app pool is actually running in classic mode.)
When this element telling it to skip validation is deleted, IIS tries to verify that the configuration is valid for integrated pipeline mode. This will fail if you have HTTP modules or HTTP handlers under the old <system.web> element. They need to be moved to <system.webServer>. You can either do this by hand, or you can use the "appcmd migrate config" command, which will update your web.config for you.
To migrate the web.config at the root of an IIS site, run appcmd migrate config like this (note the trailing slash):
appcmd migrate config "Your Site Name/"
To migrate the web.config for an application below the site root, do this:
appcmd migrate config "Your Site Name/Your App Name"
Once it's changed your web.config, you should commit the changes it made to your source-controlled copy of the web.config. Otherwise the changes will be blown away if you redeploy your web.config file from source control.

Resources