Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Using an HttpHandler to redirect a certain extension to ASPX files behind the scenes

Using an HttpHandler to redirect a certain extension to ASPX files behind the scenes

Scheduled Pinned Locked Moved ASP.NET
questionsysadminhelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kentamanos
    wrote on last edited by
    #1

    Please don't ask me why I'm doing this (trust me, it makes sense in my system), but I'd like to basically redirect requests for a certain extension (thus a handler) to an ASPX page behind the scenes. I've created a handler and set it up to handle the extension in question. In my ProcessRequest, I'd like to basically figure out which ASPX page to "forward" the request to. I've tried all sorts of methods (Server.Transfer and Server.Execute for instance), but they all have their downfall. One problem is the ASPX page in question always sets his form "action" to the name of his own page (ending in ASPX). I'd like the "action" to be the URL I'm currently at (which will in turn eventually get handled by the same ASPX page). I figured out a cheesy way to get the action to properly have the correct output by using the Server.Execute overload that allows you to redirect the output to a TextWriter and then modifying the output and sending that out. The problem with that approach is now the IsPostback of the actual page never thinks it's a post back and controls never get their events fired. Does anyone know of a way to do what I'm trying to do?


    I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
    -David St. Hubbins

    I 1 Reply Last reply
    0
    • K Kentamanos

      Please don't ask me why I'm doing this (trust me, it makes sense in my system), but I'd like to basically redirect requests for a certain extension (thus a handler) to an ASPX page behind the scenes. I've created a handler and set it up to handle the extension in question. In my ProcessRequest, I'd like to basically figure out which ASPX page to "forward" the request to. I've tried all sorts of methods (Server.Transfer and Server.Execute for instance), but they all have their downfall. One problem is the ASPX page in question always sets his form "action" to the name of his own page (ending in ASPX). I'd like the "action" to be the URL I'm currently at (which will in turn eventually get handled by the same ASPX page). I figured out a cheesy way to get the action to properly have the correct output by using the Server.Execute overload that allows you to redirect the output to a TextWriter and then modifying the output and sending that out. The problem with that approach is now the IsPostback of the actual page never thinks it's a post back and controls never get their events fired. Does anyone know of a way to do what I'm trying to do?


      I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
      -David St. Hubbins

      I Offline
      I Offline
      ian mariano
      wrote on last edited by
      #2

      Just write an ISAPI filter to capture the request and redirect (passing the appropriate arguments you get parsing the request) to wherever you want, be it another ISAPI filter, ASPX page, other server, etc.

      Ian Mariano - http://www.ian-space.com/
      "We are all wave equations in the information matrix of the universe" - me

      K 1 Reply Last reply
      0
      • I ian mariano

        Just write an ISAPI filter to capture the request and redirect (passing the appropriate arguments you get parsing the request) to wherever you want, be it another ISAPI filter, ASPX page, other server, etc.

        Ian Mariano - http://www.ian-space.com/
        "We are all wave equations in the information matrix of the universe" - me

        K Offline
        K Offline
        Kentamanos
        wrote on last edited by
        #3

        The problem is if you forward it to an ASPX page (via Server.Transfer or other methods) the underlying ASPX page still generates a FORM with an ACTION attribute with its name. In other words, if Page.xxx redirected to Page.aspx, the page that's generated still goes to Page.aspx. I want it to post to Page.xxx and have that page forward the post values to Page.aspx. It's hard to explain exactly why I want this (without going into a lot of details), but here's what I'm trying to do in a nutshell 1. Accepts all request of a given extension (easy, use a HttpHandler) 2. Based upon the requested URL (what's in the browser's address bar basically), it then determines which underlying ASPX page to actually load 3. Have that ASPX generate itself and have the output POST to the original request's URL (so that the POST comes in the same way as the original GET) I can currently use some things in my HttpHandler like Server.Execute, but the underlying ASPX page still generates it's own name as the action attribute in the POST. I can then modify the ASPX page's output to get the proper action in, but then IsPostback and events in general stop working inside the ASPX page.


        I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
        -David St. Hubbins

        I 1 Reply Last reply
        0
        • K Kentamanos

          The problem is if you forward it to an ASPX page (via Server.Transfer or other methods) the underlying ASPX page still generates a FORM with an ACTION attribute with its name. In other words, if Page.xxx redirected to Page.aspx, the page that's generated still goes to Page.aspx. I want it to post to Page.xxx and have that page forward the post values to Page.aspx. It's hard to explain exactly why I want this (without going into a lot of details), but here's what I'm trying to do in a nutshell 1. Accepts all request of a given extension (easy, use a HttpHandler) 2. Based upon the requested URL (what's in the browser's address bar basically), it then determines which underlying ASPX page to actually load 3. Have that ASPX generate itself and have the output POST to the original request's URL (so that the POST comes in the same way as the original GET) I can currently use some things in my HttpHandler like Server.Execute, but the underlying ASPX page still generates it's own name as the action attribute in the POST. I can then modify the ASPX page's output to get the proper action in, but then IsPostback and events in general stop working inside the ASPX page.


          I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
          -David St. Hubbins

          I Offline
          I Offline
          ian mariano
          wrote on last edited by
          #4

          Ahh. Why not write a custom HTTP POST request from the original page, call the desired page, and return the results. You'll just hijack the Response... 1. Request comes in to your handler 2. Handler determines the page it needs to fulfill the request 3. Handler builds the proper POST request and submits it using WebClient.OpenWrite, capturing the returned Stream and writing it back on the Handler's Response stream. Basically, you're creating behind the scenes web client to do the dirty work of calling the appropriate page on behalf of the original caller. From the perspective of the original caller, they don't ever leave the original URL.

          Ian Mariano - http://www.ian-space.com/
          "We are all wave equations in the information matrix of the universe" - me

          K 1 Reply Last reply
          0
          • I ian mariano

            Ahh. Why not write a custom HTTP POST request from the original page, call the desired page, and return the results. You'll just hijack the Response... 1. Request comes in to your handler 2. Handler determines the page it needs to fulfill the request 3. Handler builds the proper POST request and submits it using WebClient.OpenWrite, capturing the returned Stream and writing it back on the Handler's Response stream. Basically, you're creating behind the scenes web client to do the dirty work of calling the appropriate page on behalf of the original caller. From the perspective of the original caller, they don't ever leave the original URL.

            Ian Mariano - http://www.ian-space.com/
            "We are all wave equations in the information matrix of the universe" - me

            K Offline
            K Offline
            Kentamanos
            wrote on last edited by
            #5

            It seems a little bit hackish, but that might actually work ;). It's almost like a proxy server at that point. I found a pretty cool thread on dotnet247.com after finding the highly undocumented "PageParser" class. This approach might actually work for me: PageParser idea I'm going to try that approach later and see what happens.


            I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
            -David St. Hubbins

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups