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.
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.
Item” data is live for single HTTP request/Response where HttpContext. Current. Session data is live throughout user's session.
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.
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.
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: http Host: localhost Port: 950 PathAndQuery: /m/pages/SearchResults.aspx?search=knight&filter=kitchen
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With