473,763 Members | 8,423 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RewritePath in HttpHandler - how to?

Hello Developers,

I have a following problem: I need to write a HttpHandler rewriting requests
like:
/Resource.axd?re sid=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.Pr ocessRequest() method instead of RewritePath()
method I use Server.Transfer () it works in IE but FireFox instead of images
shows text garbage. I suspect Response.Conten tType 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.Pr ocessRequest() does not seem
to work?

Thank you for any hints.

Tomasz

Sep 24 '08 #1
3 3213
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.Respons e.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******** ******@TK2MSFTN GP06.phx.gbl...
Hello Developers,

I have a following problem: I need to write a HttpHandler rewriting
requests like:
/Resource.axd?re sid=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.Pr ocessRequest() method instead of RewritePath()
method I use Server.Transfer () it works in IE but FireFox instead of
images shows text garbage. I suspect Response.Conten tType 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.Pr ocessRequest() 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.Ite ms). 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/HTTPHandlersFor Images.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****@microsof t.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?re sid=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.Pr ocessRequest() method instead of RewritePath()
method I use Server.Transfer () it works in IE but FireFox instead of
images
>shows text garbage. I suspect Response.Conten tType 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.Pr ocessRequest() 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****@microsof t.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?re sid=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.Pr ocessRequest() method instead of RewritePath()
method I use Server.Transfer () it works in IE but FireFox instead of
images
>shows text garbage. I suspect Response.Conten tType 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.Pr ocessRequest() 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
1405
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 with an HttpHandler instead of an HttpModule, then this is the example for you. Suppose you are deriving a piece of information from Url, like a product code. To process it, you have a page that accepts the product code as a querystring...
15
6744
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 for the past couple of years under .NET 1.1, but when it runs under ASP.NET 2.0 it has problems. Note that this is the case regardless of whether the assmbly is built against 1.1 or 2.0 We're getting the following exception stack trace: ...
3
2946
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 successfully used HttpContext.RewritePath() to send a request to different pages in one web application, but it gives me an error when I try to rewrite a path to a different web app or server. Does RewritePath() not support this? I can reroute by...
6
5729
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, static html etc. The thing is that I don't actually want these other 'pages' to exist on disk (since I don't want to have to maintain multiple aspx pages - just the content). I basically want an XML file that defines the content 'page' path,...
0
1451
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: http://mydomain.com/Users/BobSmith/ or http://mydomain.com/Users/BobSmith The "BobSmith" didn't actually exist. My HttpModule would use RewritePath method to return a page from:
0
1164
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 URLs that my app uses, in order to select the correct output for the context. Mapping the HTTP request to a physical ASPX page seems fairly straightforward with HttpContext.RewritePath. However, I don't really want any physical ASPX pages in...
8
3900
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 need to avoid the extra round-trip to the client. I've tried Passing the page name, the full URL, and the instance of the handler class to the Transfer method, but everything gets me the same error 500. Any help would be appreciated.
0
1153
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 currently do this by making a call to the method GetCompiledPageInstance of the PageParser class. I have been trying to get information on the advantages\disadvantages of using GetCompiledPageInstance instead of using Server.transfer,...
5
7306
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 SyncHttpHandler: IHttpHandler
0
9564
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9387
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.