RewritePath in HttpHandler - how to?

  • Thread starter Thread starter Tomasz J
  • Start date Start date
T

Tomasz J

Hello Developers,

I have a following problem: I need to write a HttpHandler rewriting requests
like:
/Resource.axd?resid=1 to /someimage.gif

My HttpHandler is listed in the web.config, its ProcessRequest() method gets
called but I cannot get it to work.
If within IHttpHandler.ProcessRequest() method instead of RewritePath()
method I use Server.Transfer() it works in IE but FireFox instead of images
shows text garbage. I suspect Response.ContentType is incorrect and FireFox
is just more sensitive.

Has anyone managed to handle a similar scenario where not only path gets
rewritten but also the resource type?
Why RewritePath() called within IHttpHandler.ProcessRequest() does not seem
to work?

Thank you for any hints.

Tomasz
 
1. RewritePath is working within .NET Framework.
Meaning that you can rewrite path to mypage.aspx but not to mygif.gif

2. You right about Server.Transfer I believe that default ContentType set by
ASP.NET text/html and cause of that Firefox shows image as text.

3. Why do you need to rewrite path anyway if you doing images?
Just use Context.Response.WriteFile(..)
and set ContentType = "image"
or "image/gif" or "image/jpeg"
I believe "image" will be sufficient.

George,
 
Hi Tomasz,

I agree to what George has suggested. For such scenario, since
Context.Rewrite path will make the request continually be processed by
ASP.NET runtime. That means rewrite path to a static file type(such as jpg,
css which is directly configured to be handled by IIS) will not work. My
suggestion is you create another custom handler(such as a static resource
handler) which will accept request and write out the certain file
content(jpg, css ....) according to some parameter(in querystring or
HttpContext.Items). Thus, your rewrite handler(or module) can rewrite the
path to that custom handler to emit those certain static resources.

Here are some articles mentioned how to build a httphandler write out
custom resource stream(image)

#Thumbnailer HTTP Handler
http://www.codeproject.com/KB/web-image/thumbnailer.aspx

#HTTP Handlers for Images in ASP.NET
http://www.c-sharpcorner.com/UploadFile/desaijm/HTTPHandlersForImages1115200
5062705AM/HTTPHandlersForImages.aspx

Please feel free to post here if you have any other thought or ideas.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
Hi Tomasz,

How are you doing? Have you got any progress on this?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
Back
Top