RewritePath in HttpHandler - how to?

Discussion in 'ASP .Net' started by Tomasz J, Sep 25, 2008.

  1. Tomasz J

    Tomasz J Guest

    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
     
    Tomasz J, Sep 25, 2008
    #1
    1. Advertisements

  2. Tomasz J

    George Guest

    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,
     
    George, Sep 25, 2008
    #2
    1. Advertisements

  3. Tomasz J

    Steven Cheng Guest

    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:
    .

    ==================================================
    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.

    --------------------
     
    Steven Cheng, Sep 25, 2008
    #3
  4. Tomasz J

    Steven Cheng Guest

    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:
    .

    ==================================================
    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.

    --------------------
     
    Steven Cheng, Sep 29, 2008
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.