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. HttpHandler and routing

HttpHandler and routing

Scheduled Pinned Locked Moved ASP.NET
csharpquestion
12 Posts 3 Posters 2 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.
  • M Mark Smithson

    Is your handler registered for the other applications? If you have a url like "../Images/go.gif" where the page url is "http://server/thisapp/pages/mypage.aspx", then the request for the image will be sent to "http://server/thisapp/Images/go.gif". If your httphandler is registered for an application at the "pages" level, you will not see the request as it is not targeted for your application. If this is the case you may be able to register your handler at the higher level ("thisapp" in this example). If this is not possible, your handler may be able to replace all the urls in the page response. I think you can use a filtered stream to alter the page output in a HttpHandler. Regards Mark Smithson

    R Offline
    R Offline
    rkb
    wrote on last edited by
    #3

    Thank you for your response. You obviously understand the problem. However, I am at a loss as to what to do next based on your input. First, you ask, "Is your handler registered for the other applications?" The handler is only registered (via web.config) in the root directory of the application. In your sample it would be the "http://server/thisapp/" directory (virtual directory). I am using this application to route pages between "server" and what I will call "remoteserver". The directory structure looks like: server remoteserver + thisapp + thisapp web.config + Images + bin go.gif handler.dll + Pages mypage.aspx The request is made for http://server/thisapp/mypage.aspx which the handler intercepts and translates that into an HttpWebRequest for http://remoteserver/thisapp/Pages/mypage.aspx. The response is the content for mypage.aspx which is displayed on "server". As the browser is rendering the page it runs across url references like: ../Images/go.gif. I would expect the browser to issue a request for this image but the handler does not see this request. So that is my problem. Replacing all of the urls would be hard as some are referenced by "ImageUrl", some by "href", etc. But if that is what I need to do. . . Would you mind explaining or giving me a reference to how I would use a filtered stream in this context? Thank you again. Kevin Burton rkevinburton@charter.net

    M 1 Reply Last reply
    0
    • R rkb

      Thank you for your response. You obviously understand the problem. However, I am at a loss as to what to do next based on your input. First, you ask, "Is your handler registered for the other applications?" The handler is only registered (via web.config) in the root directory of the application. In your sample it would be the "http://server/thisapp/" directory (virtual directory). I am using this application to route pages between "server" and what I will call "remoteserver". The directory structure looks like: server remoteserver + thisapp + thisapp web.config + Images + bin go.gif handler.dll + Pages mypage.aspx The request is made for http://server/thisapp/mypage.aspx which the handler intercepts and translates that into an HttpWebRequest for http://remoteserver/thisapp/Pages/mypage.aspx. The response is the content for mypage.aspx which is displayed on "server". As the browser is rendering the page it runs across url references like: ../Images/go.gif. I would expect the browser to issue a request for this image but the handler does not see this request. So that is my problem. Replacing all of the urls would be hard as some are referenced by "ImageUrl", some by "href", etc. But if that is what I need to do. . . Would you mind explaining or giving me a reference to how I would use a filtered stream in this context? Thank you again. Kevin Burton rkevinburton@charter.net

      M Offline
      M Offline
      Mark Smithson
      wrote on last edited by
      #4

      Hmm, Your handler appears to be registered at the appropriate location, and should be intercepting all requests for your application. I have the following comments and suggestions that may help you to get to the source of the problem. Have a look at the source in your browser to confirm that the urls being requested point to your server, or are relative to the page. Try turning on logging in IIS on both servers to confirm which servers are receiving the requests. Just to confirm that I understand what you are doing. You are intercepting all incoming requests, getting the content stream from a remote server using HttpWebRequest and writing the response to the response stream of your clients request. I presume that you have reasons for not doing a Response.Redirect to the other server. If you want some information on the filter stream, I can try and find the article I read about it in. You are correct in that it would be a pain to find and replace all the urls, and I would probably persist with trying to get your solution to work. Regards Mark Smithson

      R 2 Replies Last reply
      0
      • M Mark Smithson

        Hmm, Your handler appears to be registered at the appropriate location, and should be intercepting all requests for your application. I have the following comments and suggestions that may help you to get to the source of the problem. Have a look at the source in your browser to confirm that the urls being requested point to your server, or are relative to the page. Try turning on logging in IIS on both servers to confirm which servers are receiving the requests. Just to confirm that I understand what you are doing. You are intercepting all incoming requests, getting the content stream from a remote server using HttpWebRequest and writing the response to the response stream of your clients request. I presume that you have reasons for not doing a Response.Redirect to the other server. If you want some information on the filter stream, I can try and find the article I read about it in. You are correct in that it would be a pain to find and replace all the urls, and I would probably persist with trying to get your solution to work. Regards Mark Smithson

        R Offline
        R Offline
        rkb
        wrote on last edited by
        #5

        Mark, The only "source" that I have been able to look at is either through the debugger by setting a breakpoint in the handler or by adding multiple trace statements. Between these two debugging methods I have come to the conclusion that the request is not being issued with the .aspx page references the image with something like "../Images/go.gif". If the page is in the root directory (on the remote server) and references image like "/Images/go.gif" then the request is made and it is seen in the handler. I will try turning on logging in IIS. I had not considered that before. You are correct. I am just interecepting all of the requests in the handler and using HttpWebRequest to get the actual content. I have a handler for .aspx and one for the bitmaps (.gif, .jpg, etc.). I am not using Response.Redirect because first, I need to be able to have all of the pages and content to flow through "server". Second, there are a small number of cases where I need to intercept the response from "remoteserver" and generate my own response to the browser. Between these two requirements I need the extra control that a handler promises me. I would very much appreciate information on the filter stream if you have time. Right now I am stuck as I don't have a good viable solution. The routing seems to only work some of the time and as I explained earlier URL's that have ".." in them don't seem to generate a request so I can't forward or route that request. Regards, Kevin Burton rkevinburton@charter.net

        1 Reply Last reply
        0
        • M Mark Smithson

          Hmm, Your handler appears to be registered at the appropriate location, and should be intercepting all requests for your application. I have the following comments and suggestions that may help you to get to the source of the problem. Have a look at the source in your browser to confirm that the urls being requested point to your server, or are relative to the page. Try turning on logging in IIS on both servers to confirm which servers are receiving the requests. Just to confirm that I understand what you are doing. You are intercepting all incoming requests, getting the content stream from a remote server using HttpWebRequest and writing the response to the response stream of your clients request. I presume that you have reasons for not doing a Response.Redirect to the other server. If you want some information on the filter stream, I can try and find the article I read about it in. You are correct in that it would be a pain to find and replace all the urls, and I would probably persist with trying to get your solution to work. Regards Mark Smithson

          R Offline
          R Offline
          rkb
          wrote on last edited by
          #6

          Looking at the log does reveal some additional information. 15:38:23 127.0.0.1 GET /AMPOC/StargateStartup.aspx 200 15:38:23 127.0.0.1 GET /AMPOC/Header.aspx 200 15:38:23 127.0.0.1 GET /AMPOC/Main.aspx 200 15:38:23 127.0.0.1 GET /AMPOC/Alarm.aspx 200 15:38:23 127.0.0.1 GET /AMPOC/Default.aspx 200 15:38:23 127.0.0.1 GET /AMPOC/Images/POCLogo.gif 200 15:38:34 127.0.0.1 POST /AMPOC/Logon.aspx 200 15:38:34 127.0.0.1 GET /AMPOC/BottomFrame.aspx 200 15:38:34 127.0.0.1 GET /AMPOC/SelectUserUnit.aspx 200 15:38:34 127.0.0.1 GET /AMPOC/Images/go.gif 200 15:38:41 127.0.0.1 POST /AMPOC/SelectUserUnit.aspx 200 15:38:41 127.0.0.1 GET /Images/go.gif 404 15:39:06 127.0.0.1 POST /AMPOC/ShiftSelectTime.aspx 200 15:39:06 127.0.0.1 GET /Images/go.gif 404 15:39:16 127.0.0.1 POST /AMPOC/ShiftSelectTime.aspx 200 15:39:16 127.0.0.1 GET /Images/go.gif 404 If I look at the trace 1 4/28/2003 10:38:22 AM /StargateStartup.aspx 200 GET View Details 2 4/28/2003 10:38:23 AM /Header.aspx 200 GET View Details 3 4/28/2003 10:38:23 AM /Main.aspx 200 GET View Details 4 4/28/2003 10:38:23 AM /Alarm.aspx 200 GET View Details 5 4/28/2003 10:38:23 AM /Default.aspx 200 GET View Details 6 4/28/2003 10:38:23 AM /Images/POCLogo.gif 200 GET View Details 7 4/28/2003 10:38:33 AM /Logon.aspx 200 POST View Details 8 4/28/2003 10:38:34 AM /BottomFrame.aspx 200 GET View Details 9 4/28/2003 10:38:34 AM /SelectUserUnit.aspx 200 GET View Details 10 4/28/2003 10:38:35 AM /Images/go.gif 200 GET View Details 11 4/28/2003 10:38:41 AM /SelectUserUnit.aspx 200 POST View Details 12 4/28/2003 10:39:06 AM /ShiftSelectTime.aspx 200 POST View Details 13 4/28/2003 10:39:12 AM /ShiftSelectTime.aspx 200 POST View Details Notice that the trace does not show the request for the images (request numbers 11, 12, 13). I also see in the trace that I am getting a request (I don't know where the request is being made to) but the request gets a 404 error (which is File Not Found). Somehow it is being determined that the file is not found and the request to the handler is not getting generated which would resolve the request. Basically it looks like I need to disable this 404 error and let the handler resolve the file via HttpWebRequest. Kevin Kevin Burton rkevinburton@charter.net

          M 1 Reply Last reply
          0
          • R rkb

            Looking at the log does reveal some additional information. 15:38:23 127.0.0.1 GET /AMPOC/StargateStartup.aspx 200 15:38:23 127.0.0.1 GET /AMPOC/Header.aspx 200 15:38:23 127.0.0.1 GET /AMPOC/Main.aspx 200 15:38:23 127.0.0.1 GET /AMPOC/Alarm.aspx 200 15:38:23 127.0.0.1 GET /AMPOC/Default.aspx 200 15:38:23 127.0.0.1 GET /AMPOC/Images/POCLogo.gif 200 15:38:34 127.0.0.1 POST /AMPOC/Logon.aspx 200 15:38:34 127.0.0.1 GET /AMPOC/BottomFrame.aspx 200 15:38:34 127.0.0.1 GET /AMPOC/SelectUserUnit.aspx 200 15:38:34 127.0.0.1 GET /AMPOC/Images/go.gif 200 15:38:41 127.0.0.1 POST /AMPOC/SelectUserUnit.aspx 200 15:38:41 127.0.0.1 GET /Images/go.gif 404 15:39:06 127.0.0.1 POST /AMPOC/ShiftSelectTime.aspx 200 15:39:06 127.0.0.1 GET /Images/go.gif 404 15:39:16 127.0.0.1 POST /AMPOC/ShiftSelectTime.aspx 200 15:39:16 127.0.0.1 GET /Images/go.gif 404 If I look at the trace 1 4/28/2003 10:38:22 AM /StargateStartup.aspx 200 GET View Details 2 4/28/2003 10:38:23 AM /Header.aspx 200 GET View Details 3 4/28/2003 10:38:23 AM /Main.aspx 200 GET View Details 4 4/28/2003 10:38:23 AM /Alarm.aspx 200 GET View Details 5 4/28/2003 10:38:23 AM /Default.aspx 200 GET View Details 6 4/28/2003 10:38:23 AM /Images/POCLogo.gif 200 GET View Details 7 4/28/2003 10:38:33 AM /Logon.aspx 200 POST View Details 8 4/28/2003 10:38:34 AM /BottomFrame.aspx 200 GET View Details 9 4/28/2003 10:38:34 AM /SelectUserUnit.aspx 200 GET View Details 10 4/28/2003 10:38:35 AM /Images/go.gif 200 GET View Details 11 4/28/2003 10:38:41 AM /SelectUserUnit.aspx 200 POST View Details 12 4/28/2003 10:39:06 AM /ShiftSelectTime.aspx 200 POST View Details 13 4/28/2003 10:39:12 AM /ShiftSelectTime.aspx 200 POST View Details Notice that the trace does not show the request for the images (request numbers 11, 12, 13). I also see in the trace that I am getting a request (I don't know where the request is being made to) but the request gets a 404 error (which is File Not Found). Somehow it is being determined that the file is not found and the request to the handler is not getting generated which would resolve the request. Basically it looks like I need to disable this 404 error and let the handler resolve the file via HttpWebRequest. Kevin Kevin Burton rkevinburton@charter.net

            M Offline
            M Offline
            Mark Smithson
            wrote on last edited by
            #7

            Aha! When you register your handler with IIS (Application Mapping Dialog) there is a checkbox option to "Check that file exists". If this is checked IIS will probably return a not found (404) exception. Regards Mark Smithson

            R 1 Reply Last reply
            0
            • M Mark Smithson

              Aha! When you register your handler with IIS (Application Mapping Dialog) there is a checkbox option to "Check that file exists". If this is checked IIS will probably return a not found (404) exception. Regards Mark Smithson

              R Offline
              R Offline
              rkb
              wrote on last edited by
              #8

              The only checkbox that I have checked is "Script engine". I also have limit to "GET" set. Kevin Burton rkevinburton@charter.net

              M 1 Reply Last reply
              0
              • R rkb

                The only checkbox that I have checked is "Script engine". I also have limit to "GET" set. Kevin Burton rkevinburton@charter.net

                M Offline
                M Offline
                Mark Smithson
                wrote on last edited by
                #9

                OK Well the only thing I can think of is that the trace shows the '404' requests are to the /Images directory not /AMPOC/Images. Have you tried creating an application called Images and adding the handler there as well? Alternatively can you add your handler to the root web application, or is the server used for other things as well? I hope this works ;-) Regards Mark Smithson

                R 2 Replies Last reply
                0
                • M Mark Smithson

                  OK Well the only thing I can think of is that the trace shows the '404' requests are to the /Images directory not /AMPOC/Images. Have you tried creating an application called Images and adding the handler there as well? Alternatively can you add your handler to the root web application, or is the server used for other things as well? I hope this works ;-) Regards Mark Smithson

                  R Offline
                  R Offline
                  rkb
                  wrote on last edited by
                  #10

                  I am not sure what you mean by creating an application called "Images". Do you mean create another virtual directory that points to the Images directory and add a web.config that registers another handler? Kevin Burton rkevinburton@charter.net

                  1 Reply Last reply
                  0
                  • M Mark Smithson

                    OK Well the only thing I can think of is that the trace shows the '404' requests are to the /Images directory not /AMPOC/Images. Have you tried creating an application called Images and adding the handler there as well? Alternatively can you add your handler to the root web application, or is the server used for other things as well? I hope this works ;-) Regards Mark Smithson

                    R Offline
                    R Offline
                    rkb
                    wrote on last edited by
                    #11

                    I tried creating an Images application by creating an Images virtual directory. Looking at the IIS log it seems that when ".." is used the URL is taken as the path minus the "..". This further confuses things because then the first name after the ".." becomes the application name. If you create an application with that name then you have control of the flow again. The problem is that now (for a routing application) I have to recreate the directory structure of the remote server with little virtual directories everywhere, I need to copy the assemblies to each of these virtual directories (I have tried to use and although it is recognized it is not used to find the assembly), finally since each is a new application I get a new session ID for each application where I only want one. I am hoping that there would be a better solution. I have toyed with the idea of dedicating IIS on this server to this single task (instead of http://localhost/AMPOC/startup.aspx I would have http://localhost/startup.aspx) but I can't seem to add the application mapping to the .gif and .jpg files that I need to retrieve from the remote server (pressing "Add" gives me a dialog box where the OK button is not enabled hence I cannot add). Now I am going to see if I can edit the response so as to eliminate the ".." altogether. I obviously don't like this solution either but it may be the only way. Thank you for any other suggestions that you might have. Kevin Burton rkevinburton@charter.net

                    1 Reply Last reply
                    0
                    • R rkb

                      I have implemented an HttpHandler that handles incoming requests for .aspx pages and the .gif and .jpg files that are contained in the .aspx pages. The theory behind this application is simple when I receive the request I find the URL for the request and change the host to be another host and I instantiate an HttpWebRequest based on the new Url. Basically I do the same thing for bitmaps. I have two problems that may be related. 1) It seems that if the page references bitmaps with a "..", ie. some kind of relative path like (ImageUrl="../Images/go.gif") then the handler never receives the request. If the web pages are in the root and referenced as ImageUrl="Images/go.gif" then it works just fine. I see the request and I can forward it to the "other" computer. 2) If the page contains a reference (through a hyperlink) to another web page like href="../Shift/Logoff.aspx", I also don't see the request for this page in the handler. Any idea as to why this is happening? Any workaround? Thank you for your time and your suggestions. Kevin Burton rkevinburton@charter.net Kevin Burton rkevinburton@charter.net

                      T Offline
                      T Offline
                      The Limey
                      wrote on last edited by
                      #12
                      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