If you run your application in IIS7 Integrated mode, the http handler must be defined in
handlers element of system.webServer section (httpHandlers section works for IIS6 and IIS7 Classic mode).
If you run your application in IIS7 Integrated mode, the http handler must be defined in
handlers element of system.webServer section (httpHandlers section works for IIS6 and IIS7 Classic mode).
It will be running on IIS 6 and I have all the necessary web.config settings made.
When I debug and place a breakpoint in the handler, the pages loads without ever stepping into the handler. Any thoughts?
routes.IgnoreRoute("{handler}.ashx?{*path}", new { handler = @"image" });
</div>
<div>Just to be sure... Can you post your web.config (httpHandlers section) and global.asax.cs class?</div>
Item 1: Image path - no I don't think the path is ok. If I enter the complete path to the handler I get a controller error. (I'm using Dependency Injection, see below) Here's the html for the image tag:
<img src="ImageHandler.ashx?PhotoID=1&Size=M" alt="Photo Number 1" />
Just so you know, and this could be an issue, the location of the physical ashx file is: /Views/Shared/Imagehandler.ashx.
I did try adding the path to the img tag, but that didn't work either. No matter what I do, the handler does not get fired.
What does the routes.IgnoreRoute(...) do? It seems like it should ignore anything with this filename or extension. Is that not the case?
Here's something else that might help you, I'm using a Dependency Injector to handle the mapping to classes. Do you think I need to map this some how? I'm using the Microsoft.Practices.Unity container for the IoC. I'm not sure if this is part of the problem, but it might be.
Thanks for your help.
Here's my Global.asax class:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; using System.Configuration;
using Microsoft.Practices.Unity; using Microsoft.Practices.Unity.Configuration;
using PersonalKit.Mvc.Services; using PersonalKit.Mvc.Data; //using PersonalKit.Mvc.Core.HttpHandlers;using PersonalKit.Mvc.Web.Views.Shared;
namespace PersonalKit.Mvc.Web { public class MvcApplication : System.Web.HttpApplication { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
kahanu
Member
90 Points
147 Posts
How to use a custom HttpHandler in MVC?
Sep 15, 2008 04:56 PM|LINK
Does anyone have an example of how to use a custom HttpHandler in MVC?
I wrote a simple image handler that displays thumbnails on a view, but I can't get it to fire.
I have it set in my web.config under the httpHandlers section, and in my html like this:
The handler never fires. What am I missing? Do I need to create a route for it also?
Thanks.
MVC Central
http://www.mvccentral.net
Ahmed Abu Da...
Participant
1701 Points
295 Posts
Re: How to use a custom HttpHandler in MVC?
Sep 15, 2008 06:22 PM|LINK
You can use the handler normal like other applications, no need to routes for using it.
may be you have error on the code or wronge path or something else.
CW2
Participant
938 Points
207 Posts
Re: How to use a custom HttpHandler in MVC?
Sep 15, 2008 06:40 PM|LINK
If you run your application in IIS7 Integrated mode, the http handler must be defined in handlers element of system.webServer section (httpHandlers section works for IIS6 and IIS7 Classic mode).
maartenba
Member
368 Points
76 Posts
Re: How to use a custom HttpHandler in MVC?
Sep 16, 2008 06:11 AM|LINK
Also check http://blog.maartenballiauw.be/post/2008/05/ASPNET-MVC-custom-ActionResult.aspx, it features an image action result which just uses the standerd ASP.NET MVC lifecycle.
Order my book ASP.NET MVC 1.0 Quickly via http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book
kahanu
Member
90 Points
147 Posts
Re: How to use a custom HttpHandler in MVC?
Sep 16, 2008 06:36 PM|LINK
It doesn't seem like I have an error in my code because none is thrown. When I step through the code, it never gets to the handler.
MVC Central
http://www.mvccentral.net
kahanu
Member
90 Points
147 Posts
Re: How to use a custom HttpHandler in MVC?
Sep 16, 2008 06:38 PM|LINK
It will be running on IIS 6 and I have all the necessary web.config settings made.
When I debug and place a breakpoint in the handler, the pages loads without ever stepping into the handler. Any thoughts?
MVC Central
http://www.mvccentral.net
kahanu
Member
90 Points
147 Posts
Re: How to use a custom HttpHandler in MVC?
Sep 16, 2008 06:46 PM|LINK
Maarten, this does give me ideas. I'll give it a try. But I would still like to know why my handler never gets fired. [:S]
MVC Central
http://www.mvccentral.net
maartenba
Member
368 Points
76 Posts
Re: How to use a custom HttpHandler in MVC?
Sep 16, 2008 06:58 PM|LINK
routes.IgnoreRoute("{handler}.ashx?{*path}", new { handler = @"image" });</div>Order my book ASP.NET MVC 1.0 Quickly via http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book
kahanu
Member
90 Points
147 Posts
Re: How to use a custom HttpHandler in MVC?
Sep 17, 2008 01:55 AM|LINK
Item 1: Image path - no I don't think the path is ok. If I enter the complete path to the handler I get a controller error. (I'm using Dependency Injection, see below) Here's the html for the image tag:
Here's my web.config httpHandlers section:
Just so you know, and this could be an issue, the location of the physical ashx file is: /Views/Shared/Imagehandler.ashx.
I did try adding the path to the img tag, but that didn't work either. No matter what I do, the handler does not get fired.
What does the routes.IgnoreRoute(...) do? It seems like it should ignore anything with this filename or extension. Is that not the case?
Here's something else that might help you, I'm using a Dependency Injector to handle the mapping to classes. Do you think I need to map this some how? I'm using the Microsoft.Practices.Unity container for the IoC. I'm not sure if this is part of the problem, but it might be.
Thanks for your help.
Here's my Global.asax class:
MVC Central
http://www.mvccentral.net
maartenba
Member
368 Points
76 Posts
Re: How to use a custom HttpHandler in MVC?
Sep 17, 2008 06:13 AM|LINK
Order my book ASP.NET MVC 1.0 Quickly via http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book