HttpModule is executed for JS/CSS/Images - asp.net

Problem: HttpModule is executed for JS/CSS/Images.
Following is current Configuration/Settings:
Infrastructure:
IIS 6.0 on Microsoft Windows Server 2003 R2, Enterprise Edition, Service Pack 2
IIS VD settings:
Wildcard application mapping to C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll
UnChecked "Verify that file exists"
Technology:
.NET Framework 4.0 + ASP.NET + ASP .NET Web API
Web.config configuration:
<httpModules><add name="BeforeProcessRequest" type="UI.Web.ApplicationCode.BeforeProcessRequest,UI.Web"/>
<system.webServer>
<modules runAllManagedModulesForAllRequests="false">
<add name="BeforeProcessRequest" type="UI.Web.ApplicationCode.BeforeProcessRequest,UI.Web" preCondition="managedHandler"/>
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
<remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
</handlers>
</system.webServer>
Thanks,
Amit

Related

HTTP Patch Verb not working on windows server 2012 r2

I'm working on single page application which consumes WebApi for data manipulation. My site was hosted on Windows Server 2008 R2 (IIS 7.5.7600.16385) and working fine, however after migration to Windows Server 2012 R2 (IIS 8.5.9600.16384) HTTP PATCH VERBS are not working, api call returns with status code 400 "Bad Request". I have tried following code snippet in web.config but got no luck.
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" type="System.Web.Handlers.TransferRequestHandler" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" />
<add name="Telerik.ReportViewer.axd_*" type="Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=9.0.15.225, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" path="Telerik.ReportViewer.axd" verb="*" />
</handlers>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
Googling again and again but got nothing useful, I'm stuck here, Any help would be appreciated.
These are the web.config settings I used when I had a similar problem with PUT requests after moving servers.
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
When I tried to send API call outside from network, everything was working as expected. Further investigations reveals that network firewall policy was problematic. By mistake production server was blacklisted by NOC team.
Thanks all for your efforts :)

Implementing static files cache in asp.net mvc

I am trying to implement static files cache in the ASP.net mvc application.
What i did:
I've added into Content folder a web.config file with the following content:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="300.0:00:00" />
</staticContent>
</system.webServer>
</configuration>
In the website web.config file, i commented out some lines of code:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<!-- Commented them out
<add verb="GET" path="*.js" name="Static for js" type="System.Web.StaticFileHandler" />
<add verb="GET" path="*.css" name="Static for css" type="System.Web.StaticFileHandler" />
<add verb="GET" path="*.png" name="Static for png" type="System.Web.StaticFileHandler" />
<add verb="GET" path="*.jpg" name="Static for jpg" type="System.Web.StaticFileHandler" />
-->
</handlers>
Now, publishing the website and inspecting the resources, i get the folowing response:
I see is missing the Expire header ?! (shouldn't it be there in order for cache to work)
Does the response headers tell the browser to cache the resource for the next 25920000 seconds?
I am doing things correctly in order to cache the static files?
This is correct, and you should be fine.
Some might say you should add Expires, too, for clients which do not understand HTTP/1.1, but as already argued in the first linked article, that shouldn't be a real concern, even less now, 7 years later.

Custom IHttpHandler mapping in ASP.NET MVC

I am trying to configure a custom IHttpHandler in web.config and I don't understand the behavior I'm getting. I'm trying this using IIS express.
This is how my Sytem.WebServer section of web.config looks like:
<system.webServer>
<modules runAllManagedModulesForAllRequests="false" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="dynamicPngHandler" verb="*" path="*.png" type="ImagServingTest.HttpHandler.PureCustomPngHandler, ImagServingTest"/>
</handlers>
</system.webServer>
http ://localhost:48705/default.png (does not work, I get a 404)
http ://localhost:48705/something/default.png (does not work, I get a 404)
http ://localhost:48705/something/something/default.png (does not work, I get a 404)
http ://localhost:48705/something/something/something/default.png (works)
I don't understand why this is happening. Why does the mapping fail until I have a url with three parts after localhost?
I imagine the fact that this is an MVC4 app is important (although I can't see why).
UPDATE
I've tried this using web forms instead of MVC and it works as expected.
In the MVC project I tried moving the custom handler so it was the first on the handlers' list in web.config and it still did not work.
The reason for the request failing for those urls is that they were being covered by MVC's default routing rule: "{controller}/{action}/{id}" because all those have defaults.
I've added routes.IgnoreRoute("{ignore}.png"); to RouteConfig and I'm now seeing the behavior that I expected

Can't make ASP.NET Website cache static files

I am trying to make Asp.net website to cache static files to the browser client.
I followed these steps
My web config:
<configuration>
<!-- elements removed for readability -->
<location path="content">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="100:00:00" />
</staticContent>
</system.webServer>
</location>
</configuration>
However, requesting a js file from the Content folder does not cache the file:
What i am doing wrong? I really need to fix this problem.
Removing System.Web.StaticFileHandler configurations from web.config fixed the issue, but i don't know if this is the correct way to solve the problem:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<!-- Removing these rules makes the cache to work.
With them, it doesn't work
<add verb="GET" path="*.js" name="Static for js" type="System.Web.StaticFileHandler" />
<add verb="GET" path="*.css" name="Static for css" type="System.Web.StaticFileHandler" />
<add verb="GET" path="*.png" name="Static for png" type="System.Web.StaticFileHandler" />
<add verb="GET" path="*.jpg" name="Static for jpg" type="System.Web.StaticFileHandler" />
-->
</handlers>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="100:00:00" />
</staticContent>
</system.webServer>

500.0 0x800700c1 on IIS 7.5 ASP 32-bit AppPool on Windows 2008 Server x64

I'm trying to get a classic ASP application working in 32-bit mode on our new Windows 2008 Server x64 with IIS 7.5. I've created an ApplicationPool named 'TEST' that is set to ASP.NET 2.0 in Classic mode and gone into Advanced Settings and set 'Enable 32-Bit Applications' to true for this new AppPool.
I assigned a single web application on our server to this new AppPool and try to load it in the browser. It gives me a 500.0 error 0x800700c1 which is the error for not a valid Win32 application (re:http://blogs.msdn.com/b/rakkimk/archive/2007/06/09/problems-with-32-bit-asp-net-2-0-dlls-on-a-windows-2003-server-64-bit.aspx)
As soon as I go back into my AppPool and change the enable 32-bit back to false, the particular web application runs fine. However, there is one piece of the application that will need to run in 32-bit mode which is why I'm trying to get the site to work in 32-bit mode.
I feel like I'm missing something but that 'something' doesn't seem to exist on any websites that tell you the only thing you need to do is enabled 32-bit applications in the AppPool and assign the site to that AppPool.
This issue was resolved by removing Handler Mapping under the 32-bit application folder that did not have 32-bit modules available. In this particular instance, ColdFusion 9 64bit was installed on the server and it's Handler Mapping under the folder was causing the 500.0 issue. I removed the following Handler Mappings:
<add name="AboMapperCustom-1207286671" path="*" verb="*" modules="IsapiModule" scriptProcessor="D:\UPSDATA\JRun4\lib\wsconfig\1\jrun_iis6_wildcard.dll" requireAccess="None" responseBufferLimit="0" />
<add name="AboMapperCustom-1207286690" path="*.jsp" verb="*" modules="IsapiModule" scriptProcessor="D:\UPSDATA\JRun4\lib\wsconfig\jrun_iis6.dll" requireAccess="Script" responseBufferLimit="0" />
<add name="AboMapperCustom-1207286691" path="*.jws" verb="*" modules="IsapiModule" scriptProcessor="D:\UPSDATA\JRun4\lib\wsconfig\jrun_iis6.dll" requireAccess="Script" responseBufferLimit="0" />
<add name="AboMapperCustom-1207286692" path="*.cfm" verb="*" modules="IsapiModule" scriptProcessor="D:\UPSDATA\JRun4\lib\wsconfig\jrun_iis6.dll" requireAccess="Script" responseBufferLimit="0" />
<add name="AboMapperCustom-1207286693" path="*.cfml" verb="*" modules="IsapiModule" scriptProcessor="D:\UPSDATA\JRun4\lib\wsconfig\jrun_iis6.dll" requireAccess="Script" responseBufferLimit="0" />
<add name="AboMapperCustom-1207286694" path="*.cfc" verb="*" modules="IsapiModule" scriptProcessor="D:\UPSDATA\JRun4\lib\wsconfig\jrun_iis6.dll" requireAccess="Script" responseBufferLimit="0" />
<add name="AboMapperCustom-1207286695" path="*.cfr" verb="*" modules="IsapiModule" scriptProcessor="D:\UPSDATA\JRun4\lib\wsconfig\jrun_iis6.dll" requireAccess="Script" responseBufferLimit="0" />
<add name="AboMapperCustom-1207286696" path="*.cfswf" verb="*" modules="IsapiModule" scriptProcessor="D:\UPSDATA\JRun4\lib\wsconfig\jrun_iis6.dll" requireAccess="Script" responseBufferLimit="0" />
<add name="AboMapperCustom-1207286697" path="*.hbmxml" verb="*" modules="IsapiModule" scriptProcessor="D:\UPSDATA\JRun4\lib\wsconfig\jrun_iis6.dll" requireAccess="Script" responseBufferLimit="0" />
<add name="AboMapperCustom-1207286698" path="*.hbmxml" verb="*" modules="IsapiModule" scriptProcessor="D:\UPSDATA\JRun4\lib\wsconfig\jrun_iis6.dll" requireAccess="Script" responseBufferLimit="0" />

Resources