RewritePath in HttpHandler - how to?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tomasz J

    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

  • George

    #2
    Re: RewritePath in HttpHandler - how to?

    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" <oegweb@nospam. nospamwrote in message
    news:OFfuvrpHJH A.4816@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

    Comment

    • Steven Cheng

      #3
      RE: RewritePath in HttpHandler - how to?

      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 Handlers for Images in ASP.NET

      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:
      msdnmg@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" <oegweb@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
      >
      >

      Comment

      • Steven Cheng

        #4
        RE: RewritePath in HttpHandler - how to?

        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:
        msdnmg@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" <oegweb@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
        >
        >

        Comment

        Working...