Get current domain in ASMX

In C # in the asmx web service, how do I get the current domain on which the web service was called? HttpContext.Current.Request.Url.Host returns the view of what I want, but instead of http://mydomain.com/Folder/Mywebservice.asmx I just need http://mydomain.com . I know that I can just cut off this chain, but it seems very elegant. Thanks

+6
c # web-services asmx
source share
2 answers

Uri.GetLeftPart helps here:

 Request.Url.GetLeftPart(UriPartial.Authority) 
+6
source share

In VB.Net, I used ...

 With HttpContext.Current.Request.Url sDomain=.Scheme & System.Uri.SchemeDelimiter & .Host End With 

Or if you need a port, then ...

 With HttpContext.Current.Request.Url sDomain=.Scheme & System.Uri.SchemeDelimiter & .Host & IIf(.IsDefaultPort,"",":") & .Port End With 

Easy to convert to C #;)

+2
source share

All Articles