In my global.asax I'm wiring up some services via AutoFac for DI/IoC.

One of these services would like to know the domain name and port of the current website.

for example:-

builder.RegisterType<AuthenticationService>()
                .As<IAuthenticationService>()
                .WithParameter("localhostServer", new Uri(?????))
                .SingleInstance();

this is some configuration stuff.

I have no idea how to pass in the server ip and port, via a new Uri instance when I'm doing this in my global.asax Application_Start()

Update: Server == IIS7, integrated mode. (not iis6 or classic mode).

有帮助吗?

解决方案

I don't think there is a sure way to do this:

  • IIS can map a number of ips, hostnames and ports to a web application
  • Each request can be bound to a different one

You probably need to do one of these things:

  • change your code so the binding is only needed when you have a request and not at application start
  • if you know the correct value before hand , you can set it by storing it via a configuration key
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top