Alexey  Koptyaev Alexey Koptyaev - 1 month ago 4x
ASP.NET (C#) Question

How to get current hosting address without Request

I have a Collector service which receives information via RabbitMQ about all currently running services - service name and host address. And now I need to implement Sender-part in each WebApi service I have. I don't want to make this sender class a controller, because I want to send info to Collector by raising an event each minute and because of that I can't use Request.RequestUri... and so on. Now it works manually - by calling Get method that gets host address and sends a message (raises an event). So, I need somehow make my code to know about where is it hosted. Is there any way of doing that?

And if there isn't, what if a best practice of solving this problem by using Request? Because I need a hostname to send a request that gets hostname... makes no sense.



Found a solution to my question here

bindings section contains exactly what I needed to get.