views:

996

answers:

5

I'm wondering how I can get the url from the browser in asp.net. I have a page that I use globalization/localization for and I am redirecting (via server not code) from www.spanishversion.com to www.englishversion.com but the url is masked to still say www.spanishversion.com. I want to get what the browser's url is but when I try things like

Request.Url.ToString() Request.Url.OriginalUrl Request.Path Request.RawUrl Request.ServerVariables["SERVER_NAME"]

it always comes back as www.englishversion.com. Is there a way that I can explicitly read the url from the browser?

Thanks.

A: 

You can do this using Javascript, with location.href.

Greg Hewgill
Is there a way I could get to this from managed code? I'm needing the url in .net so I can set the current culture
Marcus King
An ugly solution would be to first render a skeleton page that contains no localised content, then use AJAX on the client side that passes the location.href to the server, and the server can return the content to fill the rest of the page, which the client can do with .innerHTML. Not recommended!
Greg Hewgill
A: 

Try with Request.Url.Host

CMS
Tried that too. www.englishverison.com is what is returned.
Marcus King
A: 

try

HttpContext.Current.Request.Url.PathAndQuery

from MSDN

I use it to set variables in a master page.

craigmoliver
A: 

try

Request.Rawurl

Binu
A: 

I think Request.Url.AbsoluteUri is your friend.