Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have 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 cases 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.

like image 975
Amin Sayed Avatar asked Nov 07 '12 15:11

Amin Sayed


People also ask

What is HttpContext request?

HTTPContext. Current is a static property. This property is a static property of the HttpContext class. The property stores the HttpContext instance that applies to the current request. The properties of this instance are the non-static properties of the HttpContext class.

What is the difference between HttpContext current items and HttpContext current session in asp net?

Item” data is live for single HTTP request/Response where HttpContext. Current. Session data is live throughout user's session.

How use HttpContext current in .NET core?

ASP.NET Core apps access HttpContext through the IHttpContextAccessor interface and its default implementation HttpContextAccessor. It's only necessary to use IHttpContextAccessor when you need access to the HttpContext inside a service.

What is HttpContext current request ServerVariables?

HttpContext.Current.Request.ServerVariables("LOGON_USER") Request.ServerVariables("LOGON_USER") it will work only when Windows Integrated Authentication is turned on and Anonymous. Access is turned off. in this case, the Request.ServerVariables("LOGON_USER") will return the network.


2 Answers

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

like image 82
edhurtig Avatar answered Oct 01 '22 10:10

edhurtig


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: http Host: localhost Port: 950 PathAndQuery: /m/pages/SearchResults.aspx?search=knight&filter=kitchen 
like image 26
Tejs Avatar answered Oct 01 '22 11:10

Tejs