Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current domain in ASMX

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

like image 898
Matt Avatar asked Aug 04 '10 09:08

Matt


People also ask

Which method will get current application hosting domain name?

GetCurrentDomain method is determined by the domain credentials under which the application is running.


2 Answers

Uri.GetLeftPart helps here:

Request.Url.GetLeftPart(UriPartial.Authority)
like image 111
Tim Robinson Avatar answered Oct 23 '22 00:10

Tim Robinson


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# ;)

like image 39
barrylloyd Avatar answered Oct 23 '22 02:10

barrylloyd