Http handler is not getting called in asp.net? - asp.net

I have website which I opened in Visual web developer express.
In web.config , I have a handler defined B.
<add verb="GET,POST" path="*/faq*" validate="false" type="DefaultRedirectHandler" />
How to specify the location DefaultRedirectHandler which is a dll in this environment?
I created a handler.dll which contains the class B derived from IHttpHandler in bin directory but there are signs it is not used.
Also, I tried
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="ASP Wild" path="*" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
<add name="SampleHandler" verb="*"
path="*"
type="DefaultRedirectHandler,handler.dll"
resourceType="Unspecified" />
</handlers>
Is there some log I can look at if this handler is called elsewhere.

When you add your handler you should fully qualify its type. Include the namespace along with your type name.
<httpHandlers>
<add verb="*" path="*"
type="MyHandlerAssembly.With.A.NameSpace.IISHandler1, MyHandlerAssembly" />
</httpHandlers>
How to: Register HTTP Handlers
The assembly your handler is in must either exist in your web application's bin directory or the system assembly cache.
For more details on the configuration for HttpHandler's see the following.
add Element for httpHandlers (ASP.NET Settings Schema)
Keep in mind that there are many ASP.NET handlers added by default and defined by the system machine.config and root web.config (in your .NET library directory). If any of these handlers match your path they could be executed first. If they close the response then your handler may never get executed.
EDIT:
As for debugging what is going on on your server (i.e. what handlers in what order are getting called) you may be interested in checking out Glimpse.

Related

how to set a handler in web.config with IIS7?

I have a handler, on runtime it create a watermark on images from a specific folder. The problem is that it worked, but now it doesn't.
All that I did was to changed the hosting.
My web.config looks like this:
<handler>
<add verb="*" name="ImageWatermarkHandler" type="ImageWatermarkHandler"
path="Pics/*.jpg,Pics/*.png" modules="IsapiModule"
scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll"
resourceType="Unspecified" preCondition="integratedMode" />
</handler>
Can you please help me?
Under IIS 7, you have to specify custom http handlers and modules under the configuration/system.webServer/handlers element of your web.config (unlike older IIS versions, where the element is configuration/system.web/httpHandlers).
There's difference between integrated mode (you only need the handlers part) and classic mode(you need both handlers and httpHandlers). For details see the MSDN entry
Edit: At first I haven't noticed the precondition for integrated mode, could it be that the new hosting runs your app in classic mode?
your config file should look like this,
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="Pics/*.jpg,Pics/*.png" type="ImageWatermarkHandler"/>
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add verb="*" path="Pics/*.jpg,Pics/*.png" name="ImageWatermarkHandler" type="ImageWatermarkHandler"/>
</handlers>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
for more information,
http://msdn.microsoft.com/en-us/library/bb515343.aspx

Internal Server Error with httpHandlers section of web.config

I have an asp.net website using the form controls from Telerik. It's just moved to a new server but I keep getting a 500 Internal Server Error.
Removing the httpHandlers section of the web.config makes server error go away, although then it complains if there is a Telerik control on the page. The whole config file is valid XML. Is there anything wrong with this code?
<httpHandlers>
<add path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource, Telerik.Web.UI, Version=2008.2.826.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" validate="false"/>
</httpHandlers>
I see you mention it has just moved to a new server. Was this an IIS6 to IIS7+ migration?
IIS7 uses <system.webServer\handlers> instead of the IIS6 <httpHandlers> section. On top of this it will throw an error by default if you have the settings in the old section even if the new section is populated correctly.
Try this:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<!-- modules here -->
</modules>
<handlers>
<!-- modules here -->
<add name="Telerik.Web.UI.WebResource" path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource, Telerik.Web.UI, Version=2008.2.826.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" />
</handlers>
</system.webServer>
The validateIntegratedModeConfiguration="false" will allow you to keep your httpHandlers section populated without throwing an error (useful if you are debugging on a cassini / iis6 server) and the entry in the <handlers> section will configure it for your IIS7 server.
The runAllManagedModulesForAllRequests="true" is not strictly required but you will probably find yourself needing it if you are new to configuring IIS7 :)
Is the new server perhaps running IIS7?
Then try this
<system.webServer>
<handlers>
<add path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource, Telerik.Web.UI, Version=2008.2.826.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" validate="false"/>
</handlers>
</system.webServer>
Also, make sure you have the exact version that you have specified in the Handlers section. You do not actually need the Version, Culture, and Public Token parameters specified in your web.config in order for it to work. They are there incase you are using more than one version in your application. Without them being specified, the server will use the first one that it finds referenced in your project. So, if you are only using one version of an assembly, you can omit the parameters.
Make sure that you have the Telerik DLL Telerik.Web.UI.dll referenced in your project and that CopyLocal is set to "true". Also, make sure (using File | Properties) that you have the right version on the server, too.

Problem mapping HttpHandler --> HTTP Error 404 Not Found

I am having problems trying to map an HttpHandler in the web.config.
This is the relevant config bit:
<httpHandlers>
<add verb="*" path="*.hndlr" type="MyAssembly.MyHandler, MyAssembly" validate="false" />
</httpHandlers>
When I navigate to http://localhost/myApp/whatever.hndlr I am getting a server error 404 (not found).
It's the 1st time I am hooking up an HttpHandler so I might be missing something - any help appreciated!
UPDATE:
I managed to get it working using both answers so far - who's able to explain why it works gets the answer marked!
This is my config (won't work if you don't have both - I am running IIS7 in classic mode)
System.web:
<httpHandlers>
<add verb="*" path="*MyHandler.hndlr" type="MyAssembly.MyAssemblyHandler, MyAssembly" validate="false"/>
</httpHandlers>
System.webserver:
<handlers>
<add name="MyHandler" verb="*" path="*MyHandler.hndlr" type="MyAssembly.MyAssemblyHandler, MyAssembly" validate="false" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script"/>
</handlers>
Are you using IIS7, if so is the application pool running in classic or pipelined mode? If it is IIS7 in pipelined mode then the handler reference needs to go into the following section
<system.webServer>
<handlers>
</handlers>
<system.webServer>
rather than in the following section.
<system.web>
<httpHandlers>
</httpHandlers>
</system.web>
Just as a guide for those stuck with this problem I found the crucial attribute to be..
resourceType="Unspecified"
I originally followed a Microsoft example to set this up and they had it as
resourceType="File"
which just kept giving me 404 errors. My HTTPHandler is returning graphics.
Hope this helps :)
i am using IIS7, the solution is:
in section
<system.web>
<httpHandlers>
<add verb="*" path="*.ashx" type="CVOS.MyDocumentHandler"/>
</httpHandlers>
<system.web>
and section
<system.webServer>
<handlers>
<add name="pdfHandler" verb="*" path="*.ashx" type="CVOS.MyDocumentHandler" />
</handlers>
</system.webServer>
What is the extension of your handler? If you are using a custom extension like .hndlr you may also need to add a ScriptMap in IIS and point it to the ASP.NET runtime so that IIS can forward the request to the correct processor.
In IIS7 go to your website
Under the IIS group go to Handler Mappings
Under Actions click Add Script Map
Set Request Path to *.hndlr
Set Path to the ASP.NET runtime (%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll) or whatever version you are running.
Then in your web.config you will need to register the handler in the appropriate section as described in the other answer.
It is also possible to experience this error if you have set up the handler for 32 bit, but you are running in 64 bit (or vice versa). It's easy to set up both and have all the bases covered.
Note "preCondition", and "scriptProcessor" differences.
<handlers>
<add name="MyHandler_32bit" verb="*" path="*MyHandler.hndlr" preCondition="bitness32" type="MyAssembly.MyAssemblyHandler, MyAssembly" validate="false" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" />
<add name="MyHandler_64bit" verb="*" path="*MyHandler.hndlr" preCondition="bitness64" type="MyAssembly.MyAssemblyHandler, MyAssembly" validate="false" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" />
</handlers>
None of the previous answers worked for me.
I'm using IIS 8.5, .Net v4.0, Integrated, and was still getting a 404 with the following handler config:
<system.webServer>
<handlers>
<add name="testEmail" path="*.em" verb="*" type="MyApp.testRazorEmailHandler, MyApp" resourceType="Unspecified" requireAccess="Script" />
</handlers>
</system.webServer>
I enabled tracing and found the following :
116. -HANDLER_CHANGED
OldHandlerName testEmail
NewHandlerName System.Web.Mvc.MvcHandler
NewHandlerModules ManagedPipelineHandler
NewHandlerScriptProcessor
NewHandlerType System.Web.Mvc.MvcHandler, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
As you can see it looks like it had correctly picked up the request using my custom HttpHandler testEmail but MVC had stolen it.
I opened my route definitions in RouteConfig.cs and found that adding:
routes.IgnoreRoute("{resource}.em");
I got it to ignore requests meant for my Handler.
Hope this helps someone - I was tearing my hair out!
Hopefully my solution will help others. On a server move from IIS6 to 7.5, both .Net 4.0 Integrated, I had a Captcha control that quit working. It turns out that removing this attribute preCondition="integratedMode,runtimeVersionv2.0" from the <add> node in <system.webserver><handlers> resolved the issue.
This seems to be an edge case, but I had a customer where our httpHandler used in our application did not work on any of their servers. The handler pointed to an .ashx page and it was called from JavaScript.
The handler mapping showed up in IIS, the handler factory was there, but I would get a 404 when the browser requested the ashx page associated with the handler. After many different attempts to fix we finally browsed to the file in IIS on the server and it specifically showed a 404.7 being returned with this message.
•Request filtering is configured for the Web server and the file extension for this request is explicitly denied.
•Verify the configuration/system.webServer/security/requestFiltering/fileExtensions settings in applicationhost.config and web.config.
If you get this then Request Filtering is enabled for the .ashx extension at either your app or site level. Go to the Request Filtering option in IIS at both your site and app level and verify that the extension is not blocked. There are two different ways Request Filtering can be configured.
The default seems to be that it explicitly blocks only file extensions that are configured in the list (blacklist). The other way it can be configured is that only files specifically configured as allowed in the list are let through (whitelist). This second option is how the customer had configured all of their Windows Servers by default and it turns out that the .ashx file extension was not in the list of allowed extensions.
This is the first thread that appears when I look for a verb that responds with a 404. In my case the solution was a configuration of VS
Tools > Options > Web projects > [x] Use 64 bit version
Sorry, my VS is in spanish

Wildcard HttpHandler not handling Static Files

I had a look through some of the older questions, but I can't find anything.
I have a Wildcard HttpHandler on my web app which is processing the url and working out if it can do anything with it
If it can't, then the StaticFile Handler should pick it up and just serve it as a static file (like an html file).
The problem is, it's going through the Wildcard handler, then seemingly not going to the StaticFileHander. Is there something I need to do to the Wildcard handler, or in the web config?
This is my web.config:
<add name="Wildcard" path="*" verb="*" type="Rewriter.RewriterHttpModule"
modules="IsapiModule" requireAccess="None" allowPathInfo="false"
preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile" path="*.*" verb="*"
modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule"
scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"
resourceType="File" requireAccess="Read" allowPathInfo="false" preCondition=""
responseBufferLimit="4194304" />
Perhaps your HttpHandler should pass off the request to the StaticFileHandler explicitly.
To follow up on what Hunter said, yes, perhaps add this entry to your Web.Config following the first wildcard mapping:
<add verb="*" path="*" type="System.Web.StaticFileHandler" />
Just a thought. Haven't tested this or anything.
Check the application pool pipeline mode. If it is Classic than you have to configure your handlers in the <httpHandlers> section. If it is Integrated you should use the <handlers> section in web.config.

Is it possible to change IIS settings from web config

I'm using url rewriting.net. I'm testing web on the local host, it is successfully work. But When i deploying web to remote host, url rewriting not work. Problem is (The resource cannot be found). I found problem. My deployed remote host IIS configuration is (Virtual dir->Properties->Home directory->Application Mapping->.aspx->Edit->"Check that file exist" is checked). I need to uncheck them. But my deployed host control panel not have a application mapping function.
How to uncheck this option using web.config?
Is it possible?
Has you another idea?
IIS6
If this is IIS6 then unfortunately there is no way to change the script map settings via your ASP.NET web.config file.
You would need to find a hoster that permitted this configuration change via their control panel, or ask your present hoster (nicely) to change this for you.
IIS7
If this is IIS7 then you need to add (if it doesn't already exist) a <system.webServer /> configuration section to your web.config file and modify the handler behaviour:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<!-- remove existing handlers -->
<remove name="PageHandlerFactory-ISAPI-2.0" />
<remove name="PageHandlerFactory-Integrated" />
<!-- add back but set resourceType="Unspecified" to prevent
checking if file exists -->
<add name="PageHandlerFactory-ISAPI-2.0"
resourceType="Unspecified"
path="*.aspx"
verb="GET,HEAD,POST,DEBUG"
modules="IsapiModule"
scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"
requireAccess="Script"
preCondition="classicMode,runtimeVersionv2.0,bitness32"
responseBufferLimit="0" />
<add name="PageHandlerFactory-Integrated"
resourceType="Unspecified"
path="*.aspx"
verb="GET,HEAD,POST,DEBUG"
type="System.Web.UI.PageHandlerFactory"
preCondition="integratedMode" />
</handlers>
</system.webServer>
</configuration>
This will only work if your hoster has delegated read/write access to the Handler Mappings feature.
I'd be fairly surprised though if this was IIS 7 and the PageHandlerFactory-ISAPI-2.0 and PageHandlerFactory-Integrated handler were configured as resourceType="File" or resourceType="Either". Out of the box they're configured not to check for the existence of files and folders.

Resources