As far as i know asp.net has been integrated with IIS.
That is to say, asp.net runtime is always hosted in IIS7 no matter the incoming request is.
ie. An .aspx request or others static files request like .html or .jpg.
We know that in IIS6, aspnet_isapi.dll will be loaded to create asp.net runtime and run asp.net only when requests such as .aspx,.ashx arrive.
Now that asp.net has been integrated with IIS7 in "Integrated Mode" what's the usage of aspnet_isapi.dll? Is it the reason why we can still see aspnet_isapi.dll in iis7 is compatibility ?
In a nutshell, it's only for classic mode.
With classic pipeline mode the ASP.NET is plugged into the IIS request processing pipeline as an ISAPI extension - exactly the same way as it was in IIS 6. In fact, if you open %WINDIR%\system32\inetsrv\config\applicationHost.config file and locate the section inside of it you can see how IIS is configured to map ASP.NET specific requests to the aspnet_isapi.dll:
<handlers accessPolicy="Read, Script">
...
<add name="PageHandlerFactory-ISAPI-2.0"
path="*.aspx" verb="GET,HEAD,POST,DEBUG"
modules="IsapiModule"
scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"
preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0" />
...
</handlers>
Notice the preCondition attribute for the handler mapping. Among other things this attribute is set to classicMode, which ensures that this handler mapping only takes effect when the application pool is configured to run in classic mode.
Related
IIS Express is producing 403.14 Forbidden errors when a URL that would otherwise be handled through ASP.NET URL routing happens to correspond to a physical folder in my ASP.NET project. (The folder contains only code, and it's coincidental that the folder name happens to match the URL of a page; my URL structure is determined dynamically by a database, and users can edit that structure, so although I could just rename my project folder, in general I can't prevent this sort of collision occurring.)
This seems to be happening because the DirectoryListingModule steps in to handle the request, and then promptly fails it because directory browsing is disabled. I've tried removing this:
<system.webServer>
<handlers>
<remove name="StaticFile" />
<add name="StaticFile" path="*" verb="*"
modules="StaticFileModule" resourceType="Either" requireAccess="Read" />
</handlers>
</system.webServer>
That removes the default StaticFile handler configuration, which has modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule", and replaces it with a configuration that provides just the feature I want. (I want static file serving, but I have no need for directory listing or default documents in this app.) But the effect seems to be that IIS then produces a completely empty (0 byte) response (with a 200 status) when I hit the offending page.
So next, I tried configuring the StaticFile handler to handle only the specific physical folders that I want to make available:
<system.webServer>
<handlers>
<remove name="StaticFile" />
<add name="StaticFileCss" path="style/*.css" verb="*"
modules="StaticFileModule" resourceType="Either" requireAccess="Read" />
<add name="StaticFileScripts" path="Scripts/*" verb="*"
modules="StaticFileModule" resourceType="Either" requireAccess="Read" />
</handlers>
</system.webServer>
But when I hit the offending URL, this then produces a 404.4 - Not found error, with a message of The resource you are looking for does not have a handler associated with it.. (The Detailed Error Information on the error page says that we're in the IIS Web Core module, during the MapRequestHandler notification, the handler is Not yet determined, and there's an Error Code of 0x80070002, which is a COM HRESULT that corresponds to the Win32 ERROR_FILE_NOT_FOUND error.)
The mystifying thing is that it's not even bothering to ask ASP.NET whether it has a handler for it. IIS seems to be deciding all by itself that there definitely isn't a handler.
This only happens when there's a folder that matches the URL. All other resources with dynamically-determined URLs work just fine - IIS asks ASP.NET for a handler, ASP.NET's routing mechanism runs as normal, and if the URL corresponds to one of my dynamically defined pages, it all works fine. It's just the presence of a physical folder that stops this all from working.
I can see it's IIS doing this because I get one of the IIS-style error pages for this 404, and they have a distinctive design that's very different from the 404s produced by ASP.NET. (If I try to navigate to a URL that neither corresponds to a physical folder, nor to a dynamic resource, I get a 404 page generated by ASP.NET. So normally, IIS is definitely handing requests over to ASP.NET, but IIS is definitely getting in the way for these problematic resources.)
I tried adding this inside my <system.WebServer>, in case the problem was that IIS has decided that requests corresponding to physical folders do not meet the managedHandler precondition:
<modules runAllManagedModulesForAllRequests="true">
But that doesn't appear to help - it still doesn't get ASP.NET routing involved for URLs that correspond to physical folders. In any case, it would be suboptimal - I would prefer not to have managed handlers run for the content that I definitely want to handle as static content. I effectively want ASP.NET URL routing to be used as a backstop - I only want it to come into play if the URL definitely doesn't refer to static content.
I don't understand why ASP.NET isn't even asking ASP.NET what it thinks in this scenario. Why is it not calling into ASP.NET during the MapRequestHandler phase if there's a physical folder that happens to correspond to the URL?
When a physical file or folder with the same URL as the route is found, routes will not handle the request and the physical file will be served.
Althrough you can change this behavior by setting the RouteExistingFiles Property from the RouteCollection object to true.
Take a look at the MSDN page Scenarios when routing is not applied
I've defined an HTTP Handler and added an entry in my web.config
<add verb="GET" path="TestApp/*" type="TestApp.TestHandler, TestWebApp" />
This works as I would expect EXCEPT when I encounter static resources eg JPG, PNG files
I need my handler to also handle paths like TestApp/logo.gif but it seems like IIS has the StaticHandler registered to intercept these requests
Is there any way for my ASP.NET HttpHandler to have a chance to handle requests for static resources ONLY for the path TestApp/* but letting the IIS StaticHandler handle everything else?
And yes I realize that letting IIS handle static resources with its own handler is faster and more efficient
Your handler will intercept those requests if you are running in integrated pipeline mode:
<system.webServer>
<handlers>
<add name="TestHandler" path="TestApp/*" verb="GET" type="TestApp.TestHandler, TestWebApp" />
</handlers>
</system.webServer>
If you are running in Classic Pipeline mode you will have to register an ISAPI filter in IIS in order to make those requests go through the managed handler.
You should add this to your web.config:
<modules runAllManagedModulesForAllRequests="true" />
This will ensure that even requests for static files are being passed through the .net pipeline.
I wanted to know what is the meaning of
<modules runAllManagedModulesForAllRequests="true" />
I am using IIS 7.5 and I have a simple web application. Do I need to write this in my web.config file.
I have also written few http handler for jquery ajax call.
I am using form authentication and asp.net 4.0.
How can I determine which module I have to run and which is not to be?
Modules Preconditions:
The IIS core engine uses preconditions to determine when to enable a particular module. Performance reasons, for example, might determine that you only want to execute managed modules for requests that also go to a managed handler. The precondition in the following example (precondition="managedHandler") only enables the forms authentication module for requests that are also handled by a managed handler, such as requests to .aspx or .asmx files:
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" preCondition="managedHandler" />
If you remove the attribute precondition="managedHandler", Forms Authentication also applies to content that is not served by managed handlers, such as .html, .jpg, .doc, but also for classic ASP (.asp) or PHP (.php) extensions. See "How to Take Advantage of IIS Integrated Pipeline" for an example of enabling ASP.NET modules to run for all content.
You can also use a shortcut to enable all managed (ASP.NET) modules to run for all requests in your application, regardless of the "managedHandler" precondition.
To enable all managed modules to run for all requests without configuring each module entry to remove the "managedHandler" precondition, use the runAllManagedModulesForAllRequests property in the <modules> section:
<modules runAllManagedModulesForAllRequests="true" />
When you use this property, the "managedHandler" precondition has no effect and all managed modules run for all requests.
Copied from IIS Modules Overview: Preconditions
I have httpHandler that handles the jpg file. When a request for a jpg image comes to server it is forwareded to handler. This works fine until i implemented finger printing for google page speed rule.
Now it gets called for http://static2.localnatamam.com/Uploaded/Image/Image_Haroon_ur_Rasheed_78.jpg
but not for
http://static2.localnatamam.com/Uploaded/Image/_SFP634229374826528000EFP_Image_Haroon_ur_Rasheed_78.jpg
First file exist in directory but second does not exist as the second URL is finger printed and i want to get the request in Handler but handler never gets evoked.
I think its might be IIS 7 configuration that is returning 404 rather than passing it to handler.
Please any advise or configuration that can route request to httphandler no matter if exist or not.
I am using asp.net MVC 2 with IIS 7 integreated Mode with target framework 4.0 in local enviornment so both of above URL will not open for any body.
My handler is simple IHttpHandler with the following IIS configuration
<add name="CrossDomainResourceHandler" type="MvcApplication3.HttpHandlers.CrossDomainResourceHandler" path="*.jpg" verb="*" resourceType="Unspecified" allowPathInfo="false" modules="IsapiModule" scriptProcessor="%path%\aspnet_isapi.dll"/>
Make sure you have this in your web.config file:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</system.webServer>
runAllManagedModulesForAllRequests will tell IIS to route every request through the .net pipeline so that your module will pick this request up since by default static resources like .jpg are configured to not run through asp.net.
When I create a Asp.net app and flip the appPool to "ASP.NET v4.0 Classic" it fails with the following error:
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 searching it seems to be the handler not mapping correctly for the Classic mode but I can't find out where or how to fix that.
I have the full .Net 4.0 install with VS2010 and the app works fine if I flip the appPool to Integrated. Also, it's a Windows 7 machine (I'm having the same problem on a Vista box). Thanks in advance.
Andy
I would start by calling aspnet_regiis.exe from the .net 4.0 directory.
Also you can run the following command to see the list of handlers that are configured for your server:
\windows\system32\inetsrv\appcmd.exe list config -section:handlers | findstr v4.0 | findstr Isapi
You should see the asp.net page factory, something like (in a 64-bit machine you should see them twice):
<add name="PageHandlerFactory-ISAPI-4.0_32bit" path="*.aspx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="PageHandlerFactory-ISAPI-4.0_64bit" path="*.aspx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
What worked for me was to edit the script map (double click on PageHandlerFactory-ISAPI-4.0_64bit in Handler Mappings), click Request Restrictions button, go to the Access tab, and change it from "script" to "none".
Install net framework 4.5 extension via server management(IIS Function install). You'll get things OK.
This is just a contribution to this issue. I am not saying that this WILL work for you it just might help is all:
For me this had nothing to do with the “IsapiModule” even though the exact error message I got was "HTTP Error 500.21 - Internal Server Error
Handler "PageHandlerFactory-ISAPI-4.0_32bit" has a bad module "IsapiModule" in its module list".
My scenario is that I got that error after I set “Enable 32-bit Applications” to "true" in the Application pool advanced settings for my Dot.Net 4.0 Classic Application Pool.
So on a whim, I simply changed the Pipeline Mode to “Integrated” and now it works for me. Which is silly because when I had it set to "Integrated" initially it didn't work, which is why I was using "Classic."
I hope this helps.