HttpContext.Current.Request.Url.Host what it returns?

Amin Sayed picture Amin Sayed · Nov 7, 2012 · Viewed 110.9k times · Source

I'm having a local application which has a path:

http://localhost:950/m/pages/Searchresults.aspx?search=knife&filter=kitchen

but when this goes to integration environment or perhaps the production, it will be something like

http://www.someshopping.com/m/pages/SearchResults.aspx?search=knife&filter=kitchen

For some case I need to pass just:

www.someshopping.com

to my XSLT file and in one of the function I'm using this:

string currentURL = HttpContext.Current.Request.Url.Host;

this returns me "localhost" in local environment. Will the same code return me:

www.someshopping.com in production (I DO NOT need http://)

just don't want to take any chance. So asked this silly question.

Answer

edhurtig picture edhurtig · Nov 7, 2012

Yes, as long as the url you type into the browser www.someshopping.com and you aren't using url rewriting then

string currentURL = HttpContext.Current.Request.Url.Host;

will return www.someshopping.com

Note the difference between a local debugging environment and a production environment