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
GetCurrentDomain method is determined by the domain credentials under which the application is running.
Uri.GetLeftPart
helps here:
Request.Url.GetLeftPart(UriPartial.Authority)
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# ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With