• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

Accessing Host Header within Web Services Method

I have a web service that I need to retreive the host header used to access the service.  In classic ASP, I would use Request.ServerVariables("SERVER_NAME"), but I am having a hard time doing this from within VB.NET.  In the web services "code-behind" (myservice.asmx.vb) page, I don't have access to the Request object, and if I try to use System.Web.HttpRequest object, it doesn't provide for any properties like ServerVariables, it only provides Equals and ReferenceEquals in the IntelliSense dropdowns.  I just need to be able to determine the difference if the web service is being accessed via:
     http://test1.mysite.com/myservice.asmx/mymethod
as opposed to:
     http://test2.mysite.com/myservice.asmx/mymethod

Any help is appreciated!
0
bmccleary
Asked:
bmccleary
  • 2
  • 2
2 Solutions
 
CJ_SCommented:
Try using the current httpcontext. Like

System.Web.HttpContext.Current().Request.ServerVariables("SERVER_NAME")

CJ.

0
 
AerosSagaCommented:
Dim en As System.Collections.IEnumerator

en = Request.Headers.GetEnumerator

While en.MoveNext
   Response.Write(CStr(en.Current) & "<br>")
End While

Or

Dim en As System.Collections.IEnumerator

en = Request.Headers.GetEnumerator

While en.MoveNext
   Response.Write(CStr(en.Current) & "<br>")
End While
0
 
bmcclearyAuthor Commented:
Thanks Aeros, but the problem is that I don't have access to the Request or Response objects.  When I put that code in my asmx page, it underscores bothe the Request and Response lines and states "Name 'Request' is not declared.".  My web service class inherits from System.Web.Services.WebService and the following are my imports clauses:

Imports System.Web.Services
Imports System.Text

Do I need another Imports statement?
0
 
AerosSagaCommented:
try imports system.web
0
 
bmcclearyAuthor Commented:
Thanks guys.  CJ, I didn't see your comment the first time, but that worked.  Aeros, thank you also, that seems to work as well.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now