views:

70

answers:

3

In C# in an asmx web service how do I get the current domain that the webservice was called on? HttpContext.Current.Request.Url.Host returns kindof what I want but instead of http://mydomain.com/Folder/Mywebservice.asmx I just need http://mydomain.com. I know i could just cut that string up but it seems really in-elegant. Thanks

+2  A: 

Possible duplicate of the link below -

http://stackoverflow.com/questions/61817/whats-the-best-method-in-asp-net-to-obtain-the-current-domain

You will get answer here.

Sachin Shanbhag
+1  A: 

Uri.GetLeftPart helps here:

Request.Url.GetLeftPart(UriPartial.Authority)
Tim Robinson
A: 

In VB.Net I have used...

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

Or if you care about the Port then...

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

Should be easy to convert to C# ;)

barrylloyd