host header

randy_belcher

Freshman
Joined
Dec 10, 2003
Messages
37
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.
 
Visual Basic:
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
 
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.
 
Last edited:
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.
 
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.
 
Back
Top