Original/actual request value? RRS feed

  • Question

  • User-68660285 posted
    G'day all,
    I'm attempting to validate requests to a site, and require them to conform to a set of rules, however I'm having issues catching the incorrect URIs server-side in order to validate them correctly. I have a small command line tool that will creates a request using an incorrent URI so I can debug it on the web server, within an HttpModule.
    Consider the following code.
    1. From the command line tool (pre-request):
    Uri oUri = new Uri("http://www.mysite.com//default.aspx");

    HttpWebRequest oHttpWebRequest = (HttpWebRequest)(HttpWebRequest.Create(oUri));
    Request.RequestUri: {0}", oHttpWebRequest.RequestUri.ToString());
    Output here is:
    ** Note the presence of a double trailing slash as per the original URI **
    2. From the HttpModule:
    private void HttpApplication_BeginRequest(object Sender, EventArgs E)
    Output here is:
    ** Note how the double trailing slash has been removed! **
    3. From the command line tool (post-request):
    HttpWebResponse oHttpWebResponse = (HttpWebResponse)(oHttpWebRequest.GetResponse());
    Console.WriteLine("Response.ResponseUri: {0}", oHttpWebResponse.ResponseUri.ToString());
    Output here is:
    "Response.ResponseUri: http://www.mysite.com//default.aspx"
    ** Note the presence of a double trailing slash as per the original URI **
    My question is: how can I get the actual originating request string? Obviously some formatting is automatically taking place within the ASP.NET engine, but it is still seems to be telling the client that the response is coming from the wrong place. I need to be able to trap this so I may 301 redirect the user to the correct URI.
    Any help is most appreciated, I have been banging my head against the wall over this for some time now.
    Wednesday, March 11, 2009 10:18 PM

All replies

  • User-68660285 posted
    G'day all,
    Looks like I'm on my own with this one? Here's some more information I've found anyway.
    I've written a small proxy server so I can see what's going on between the browser and IIS. As I suspected, typing a request into a browser such as http://www.mysite.com//default.aspx *is* actually forwarded to IIS in that format. There is *no* formatting of the URL taking place at this stage, it seems to be after the request has arrived in IIS itself, but before it arrives at the ASP.NET engine. The request is not logged with the double slash.
    Now, does this mean that should this link appear in my site that Google will index the content at that location under potentially *two* locations? And if that is the case, how will I trap this?
    It looks as though I need to be able to plug into the request pipeline before it arrives at the ASP.NET engine - I guess I'm looking for an HttpApplication.ActuallyReallyBeforeRequest event to hook into.
    Any thoughts or ideas here at all? ISAPI perhaps?
    Monday, March 16, 2009 7:28 PM