I am trying to redirect a user when they entire a URL in this format:
http://example.com/http://example2.com/
To the following:
http://example.com/?m=example2.com#http%3A%2F%2Fwww.example2.com%2F
I want to strip out the host of example2 and make it a query-string, then URL encode the full URL of example2 and put it as the anchor.
What is the best way to do this in asp.net? I can use mvc, iis7, or iis6. I know I could do this by mapping everything to .NET in IIS6 and then using httpcontext.rewritepath but I bet there is a better way.
Thank you.
Unfortunately, ASP.NET does not allow a colon anywhere in the URL path. Not even an escaped colon (%3A). It is only allowed in the querystring portion of the path.
This restriction is in place even before URL rewriting happens. (You’ll get the 400 Bad Request error.) In that question, the asker answered their own question with a link to Stefan from the ASP.NET team.
Of course, you can still collect the URL from your user any way you like, and format the URL or redirect in a way that ASP.NET can use.