2

I'd like to be able to get the url that the app is hosted on. There will be various ways that clients will access the service layer, through an asp.net mvc app, wcf (hosted on the mvc app).

My service layer is in a dll. Is there any way that I can get the url pointing to a specific action when a remote client uses either entry points to the system?

Shawn Mclean
  • 56,733
  • 95
  • 279
  • 406
  • See this related question: http://stackoverflow.com/questions/1288046/how-can-i-get-my-webapps-base-url-in-asp-net-mvc – Todd Price May 16 '12 at 13:52

1 Answers1

2

It is possible - but not a good thing to do. You are binding the business layer to an implementation detail which is higher layers and business layer should have no knowledge of.

You can use various OperationContext.Current properties (depending on your binding) to get to the address.

For example, OperationContext.Current.IncomingMessageHeaders can be used for HTTP or OperationContext.Current.Host.BaseAddresses if there are base addresses. You just need to evaluate which one provides the address you are looking for depending on your configuration.

Aliostad
  • 80,612
  • 21
  • 160
  • 208