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

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


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


The Host property will return the domain name you used when accessing the site. So, in your development environment, since you're requesting

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

It's returning localhost. You can break apart your URL like so:

Protocol: httpHost: localhostPort: 950PathAndQuery: /m/pages/SearchResults.aspx?search=knight&filter=kitchen


Try this:

string callbackurl = Request.Url.Host != "localhost"     ? Request.Url.Host : Request.Url.Authority;

This will work for local as well as production environment. Because the local uses url with port no that is possible using Url.Host.