Reputation: 137
I have a webservice that is used under several different websites and want to know which of the sites the request came through (and return different things depending on that data). How do I do this?
I have a website, example.com, that has one webservice in /webservice.svc . When the client comes to this site via http://client1.example.com/webservice.svc/hello I want to say "hello, client1!" and when they come through http://client2.example.com/webservice.svc/hello it should say "hello, client2!".
So client1 or client2 depending on subhost (or application directory)
Upvotes: 0
Views: 1197
Reputation: 137
Ended up getting this done with HttpContext.Current.Request.Url.ToString();
It too returned "Object reference not set to an instance of an object" originally when I tried, but found that setting [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] before my class declaration as well as in web.config did the trick and allowed access to the variables I wanted.
Upvotes: 2
Reputation: 3191
Assuming you are using WCF, you can try:
System.ServiceModel.Web.WebOperationContext.Current.IncomingRequest.Headers["Referer"]
The result will in your example be http://client1.example.com/webservice.svc/hello or http://client2.example.com/webservice.svc/hello. You can then parse that string for presence of client1 or client2.
You may want to check for nulls.
Upvotes: 1