Custom Image Handler - asp.net-mvc-3

I've got a custom image handler (.ashx) which extends IHttpHandler. Basically all it does is fetch some images from a database and make them a thumbnail if requested.
This works fine on my local machine, but when I deploy it to my IIS 6 web server my images don't display.
My question is - can anyone tell me what the procedure is for setting up a handler like this in IIS 6?
Update
The paths to my image (that don't display) look like this:
http://xxx.xx.xxx.xxx/Helpers/ImageHandler.ashx?imageid=7&thumbnail=1
I've added this to my web.config file, but still no luck:
<httpHandlers> <add verb="*.png" path="MyWeb.Helpers.ImageHandler" type="MyWeb.Helpers.ImageHandler, MyWeb"/> </httpHandlers>
Thanks.

You need configure IIS6 to map the mime types to be parsed by .NET, so that they can be called by your handler; there is more on this here.
EDIT
Also try adding this to your web.config;
<add verb="*" path="*.png" type="MyWeb.Helpers.ImageHandler, MyWeb.Helpers"/>
Hope this helps,
Matt

Related

How to allow a DELETE method with IIS Express and Web API?

I am trying to send a delete request to my Web API service via Fiddler and am getting back a 405 "Method not allowed" error.
I have read extensively about removing the "WebDAV" module in web.config and similar suggestions (WebDAV is not enabled in my applicationhost.config anyway), but nothing I have tried has worked.
My service is currently running on IIS Express 10 (launching from Visual Studio). I do have this in my web.config file:
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0"/>
I would have thought the verb="*" piece would have allowed DELETE, but it does not seem to work.
One other note - when I inspect the response in Fiddler, under the Security heading it says: Allow: GET, POST.
I am not sure where that "Allow" parameter is being set (I am new to Web API).
Any help would be greatly appreciated. Please let me know what other information you need from me and I will add it.
Thank you!
Just reproduced this by creating a new webapi project [targeting .net framework 4.7.1]
Through Fiddler, I can hit the DELETE endpoint without any changes to web.config.
Please make sure to use correct endpoint including the id parameter.
e.g http:localhost:xxxx/api/values/id // please include the id and xxxx is port number.
If http:localhost:xxxx/api/values is used without id , I get the same result 405 Method Not Allowed
Hope this helps.
You can modify the IIS Express applicationHost.config in the %userprofile%\documents\IISExpress\config folder.  To enable PUT and DELETE for extensionless Urls scroll down to the bottom of the IIS Express applicationHost.config file and look for a handler entry that starts with: <add name="ExtensionlessUrl-Integrated-4.0".... In the "verb" attribute add PUT and DELETE so the "verb" attribute looks like:  verb="GET,HEAD,POST,DEBUG,PUT,DELETE"
Update your web config like this
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/> <!-- ADD THIS -->
</modules>

Using path extensions for http handlers in IIS 8.5

I ran into a weird issue when migrating a site on to a new web server.
I have some custom handlers written and defined in my web.config:
<add name="CalendarHandler" verb="*" path="/api/Calendar" type="CalendarHandler" />
If I do not put a file extension on the path like "/api/Calendar.css" the response that comes back is a redirect loop. If I put any extension on the path it will return the correct response. Removing the extension causes a re-direct error.
The path="/api/Calendar" works just fine the old server. I have moved the site from IIS 7.5 WIN 2008 R2 to IIS 8.5 WIN 2012. I am not sure what setting I am missing in IIS. I have made sure all the handler mappings are the same and I have tried installing URL Rewrite. No luck.
I changed the path to
<add name="CalendarHandler" verb="*" path="/api/Calendar/" type="CalendarHandler" />
and it worked. For some reason IIS 8.5 did not like 'path="/api/Calendar"' the missing '/' caused the redirect loop.

elfinder with MVC 3 and IIS 7

Im trying to use elfinder in my MVC 3 application and using this .NET connector
: http://elfinderconnectornet.codeplex.com/ for elfinder. And this connector works with http handler configured in section in WebConfig. For example:
for url like :
192.168.0.17:9002/elfinder.connector?_=1347370006351&cmd=open&target=&init=true&tree=......
i have a handler in web config
<system.web>
<httpHandlers>
<add verb="*" path="elfinder.connector" type="ElFinder.Connector.Connector" />
</httpHandlers>
</system.web>
and in global.asax.cs routes.IgnoreRoute("elfinder.connector");to ignore this url in "Controller/Action" routing.
When im running this code in VisualStudio localhost all works fine but on IIS 7 i have an 404 error.
May be IIS have custom config for httphandlers? some checkbox need to be checked :)
Any idea?
I received the same error because I didn't have read permissions on the directory. You must give, at least, read permission to see the folders and files.
Hope it helps. Regards.

Routing requests that end in ".cshtml" to a controller

(This is cross-posted to the ASP.NET forms)
I'm working on the WebGit .NET project, and we are close to a "1.0" release. However, I'm having trouble getting my "Browse" controller (which pulls files out of the repository) to serve-up ".cshtml" files.
I originally had trouble with ".config" and ".cs" files as well, but I fixed that with this in the web.config:
<location path="browse">
<system.webServer>
<security>
<requestFiltering>
<fileExtensions allowUnlisted="true">
<clear />
</fileExtensions>
<hiddenSegments>
<clear />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</location>
The routing that should be handling this request (that is successfully routing everything else) is:
routes.MapRoute(
"View Blob",
"browse/{repo}/blob/{object}/{*path}",
new { controller = "Browse", action = "ViewBlob", path = UrlParameter.Optional });
Now, whenever I try to access a URL that ends in ".cshtml", it gives a 404, even though my request should have been handled by the "Browse" controller. The files I'm serving-up do not exist on disk, but are instead pulled from a git repository as blobs. Every other file extension that I have tried works just fine.
How can I fix this behavior?
EDIT: I have tried disabling WebPages like so:
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
But that appears to have no effect.
As a quick workaround, you can put a temporary browse.cshtml file at your application root and put this inside your web.config,
add key="webpages:Enabled" value="false"
This is a known bug in ASP.NET WebPages, which gets implicitly loaded when you are using MVC 3. I don't think there is a straightforward way of disabling this behavior. The only workaround is to use a different extension (specifically, one that is not listed via WebPageHttpHandler.GetRegisteredExtensions())
This will be fixed in MVC 4, however. Sorry for the inconvenience.

Html.Telerik().StyleSheetRegistrar() output file generating 404 message on asset.axd

I'm using the Telerik controls form MVC and they work great in my work/home dev environments, and in the work prod environment, but when I tried to deploy to my home prod environment (IIS7) I get a problem.
I've added the axd mime type, but wan't sure what else to do.
I read a post suggesting adding a handler, but wasn't sure if I'm setting that wrong or I'm just looking in the wrong direciton.
if you're on IIS7 make sure you add the handler to the <system.webServer><handlers> section:
<add name="MyName" path="MyName.axd" verb="*" type="NameSpace.Class, Assembly" />
I added: <add name="ScriptRegistrar" path="Access.axd" verb="*" type="Telerik.Web.Mvc.UI.ScriptRegistrar, Version=v2.0.50727" />
http://localhost:1000/asset.axd?id=sQAAAB-LCAAAAAAABADsvQdgHEmWJSYvbcp7f0r1StfgdKEIgGATJNiQQBDswYjN5pLsHWlHIymrKoHKZVZlXWYWQMztnbz33nvvvffee--997o7nU4n99__P1xmZAFs9s5K2smeIYCqyB8_fnwfPyJ-8UfT9qNHH7X5u_butGk-Gn10SX_u7ezujHfH93Ye0gfTjx619TqnX2YfPbr36f3RR_Tze7_4oxU1PKmWbb5s775ur8scb5_zV9VHj3ZGHy2pwbRaLKrlGKB_yYi_2JUv2rzM6-LtuN9gL2xwWTRtJt9__5d8_5f8PwEAAP__qtxwmrEAAAA%3d
To enable web resource combining with the Telerik Extensions you need to register the WebAssetHttpHandler in your webconfig:
IIS 7
<add name="AssetHandler" preCondition="integratedMode" verb="GET,HEAD" path="asset.axd" type="Telerik.Web.Mvc.WebAssetHttpHandler, Telerik.Web.Mvc"/>
IIS 6
<add verb="GET,HEAD" path="asset.axd" validate="false" type="Telerik.Web.Mvc.WebAssetHttpHandler, Telerik.Web.Mvc"/>
This handler enables you to use the Combine, Compress, and Cache features of the Script and StyleSheet Registrars. You can learn more and see additional config details in the Telerik online docs:
http://www.telerik.com/help/aspnet-mvc/web-assets-working-with-javascript-web-assets.html

Resources