randy_belcher Posted October 1, 2004 Posted October 1, 2004 Is it possible to capture the host header in the global.asax application_start event? I would like to set some application variables based on the host header. Like using a test database connection string if the host header is localhost or use live data if the host header is production. Thanks. Quote
*Gurus* Derek Stone Posted October 3, 2004 *Gurus* Posted October 3, 2004 Dim currentContext As System.Web.HttpContext = System.Web.HttpContext.Current Dim hostIPAddess As String If Not currentContext Is Nothing Then hostIPAddress = currentContext.Request.UserHostAddress End If Quote Posting Guidelines
randy_belcher Posted October 4, 2004 Author Posted October 4, 2004 (edited) This just returned the IP (127.0.0.1). I am looking for the url http://xxx/yyy/site.com or just the host header which is the xxx part. I tried userhostname and it returned (127.0.0.1) too. Thanks for the help. Edited October 4, 2004 by randy_belcher Quote
wessamzeidan Posted October 4, 2004 Posted October 4, 2004 you can use the Request Object. It has properties like Request.Url, Request.HostName..... Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
randy_belcher Posted October 4, 2004 Author Posted October 4, 2004 that doesn't work in the global.asa in the application_start event. I am going to check the code above on the server instead of my local machine and see if it works. Quote
randy_belcher Posted October 4, 2004 Author Posted October 4, 2004 even on the server i just get the IP address using the above code. any other suggestions Quote
randy_belcher Posted October 4, 2004 Author Posted October 4, 2004 got it. the answer is strhostIPAddess = currentContext.Request.Url.Host thanks for the help guys. you pointed me to the direction I needed to go. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.