URL request and redirect RRS feed

  • Question

  • User2093584515 posted
    Salutations, In ASP.NET when the default main page of [Site1] is hit how can I check for the URL the user used and then redirect them to that path of the current server? 1) [Site1] hosts the vitrual site that moved from an existing URL. 2) The existing domain name has been changed from [Site2] to [Site1]. 3) [Site2] no longer exists, [Site1] now hosts [Site2] on a virtual folder /name/ Thanks, Mark
    Thursday, September 2, 2004 7:57 PM

All replies

  • User-886813230 posted
    I believe you could create an HttpModule that examples the URL of the incoming request and then uses the RewritePath method to change the location that ultimately processes the request. RewritePath is part of the HttpContext class. Hope this helps.
    Friday, September 3, 2004 3:13 PM
  • User1477680884 posted
    . . .Thanks for the heads-up Bruce. I'll do some research in that direction. Took a look at your Tips and WhitePapers, good job. :-) All the best, Mark
    Friday, September 3, 2004 3:43 PM
  • User1477680884 posted
    Update. . .Decided to do it with ASP instead, works great. Dim Caught Caught = Request.ServerVariables("SERVER_NAME") If Caught = "www.site.net" Then Response.Redirect("/name/") End If
    Saturday, September 4, 2004 10:01 AM
  • User-886813230 posted
    What you're doing might work so long as the client-side supports automatic redirection. Keep in mind that when you do a Response.Redirect, you are actually sending a response containing the new location back to the client (with an HTTP status of 303, I believe). The client is then responsible for resubmiting the request to the new location. First of all, this means that every request to www.site.net will actually consist of two separate requests. Depending on how often you're doing this catch and redirect, performance could be an issue. Second, if you ever decide to hang something like a web service off of the www.site.net domain, there is a good chance that the redirection wouldn't work. Unlike browser clients, which automatically perform the redirection (for the most part), web service clients need to be coded to do so. If you want to use this technique, I'd suggest using a Server.Transfer instead. It avoids both of these problems. My other reason for suggesting the httpModule was that it was orthogonal to any future development. You don't need to inject this block of code into any entry point to the www.site.net domain. Just my two cents. :)
    Saturday, September 4, 2004 11:21 AM
  • User2093584515 posted
    . . .I'm a big fan of the new server methods .execute and .transfer but for this project server.transfer resulted in an error each time. (The resulting pages are build with server.execute methods and virtual includes) 15seconds.com has a good article on the advantages and disadvantages of using server.transfer: http://www.15seconds.com/issue/010220.htm The main reason I didn't use a .NET httpModule method for this project is that it incorporates both Flash and ASP on the default page and in a .NET environment I couldn't get past a "/" error for some reason, even in debug mode I couldn't figure out why the same migrated code wasn't working, then I tried the conversion assistant and the code it generated failed with the same error. Thanks for your input. :-)
    Saturday, September 4, 2004 3:02 PM