473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

RewritePath in HttpHandler - how to?

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

Sep 24 '08 #1
3 3186
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,

"Tomasz J" <oe****@nospam.nospamwrote in message
news:OF**************@TK2MSFTNGP06.phx.gbl...
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
Sep 25 '08 #2
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-im...umbnailer.aspx

#HTTP Handlers for Images in ASP.NET
http://www.c-sharpcorner.com/UploadF...rImages1115200
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:
ms****@microsoft.com.

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

--------------------
>From: "Tomasz J" <oe****@nospam.nospam>
Subject: RewritePath in HttpHandler - how to?
Date: Thu, 25 Sep 2008 01:11:47 +0200
>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

Sep 25 '08 #3
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:
ms****@microsoft.com.

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

--------------------
>From: "Tomasz J" <oe****@nospam.nospam>
Subject: RewritePath in HttpHandler - how to?
Date: Thu, 25 Sep 2008 01:11:47 +0200
>
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

Sep 29 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Anonieko | last post by:
Jefrey Palermo How to do Url Rewriting with just an HttpHandler (without the side-effects) - level 400 posted on Wednesday, August 10, 2005 7:21 PM If you are interested in doing Url Rewriting...
15
by: James Higgs | last post by:
For a long time, our product has had a "vanity URLs" feature where nice URLs are mapped to ASPX files in an IHttpModule implementation, using HttpContext.RewritePath(). This has worked beautifully...
3
by: asanford | last post by:
I want to create an ASP.NET web application that receives a form POST message, inspects the data, and reroutes the request to one of many different servers. I wrote an IHttpModule which...
6
by: Steve | last post by:
Hi there, I'm trying to create a new website that will have a common aspx file serve as a template. I want all other pages to use this file and 'inject' their own content i.e. user controls,...
0
by: cpnet | last post by:
I was playing around with Beta 2 of VS2005, .NET 2.0, and built an IHttpModule do allow me to have nice URL's in my web app. It was working great. I had a URL like: ...
0
by: zootius | last post by:
Hi - I'm working on a front-controller style application in ASP.NET 2.0. I have mapped all HTTP requests to ASPNET_ISAPI, and use an HttpModule to do a database lookup on the search-engine-friendly...
8
by: bryan | last post by:
I've got a custom HttpHandler to process all requests for a given extension. It gets invoked OK, but if I try to do a Server.Transfer I get an HttpException. A Response.Redirect works, but I really...
0
by: Mutley | last post by:
Hi All, I have a custom HttpHandler that handles requests for pages with my custom file extension of sfdl. Within the ProcessRequest method of the custom handler I want then to getthe page. I...
5
by: Author | last post by:
I followed the example at http://support.microsoft.com/kb/308001/EN-US/ and created my own HttpHandler. Here is the code: using System.Web; namespace MyNameSpace { public class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.