0

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).

Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
  • http://stackoverflow.com/questions/4243270/how-to-get-full-host-name-port-number-in-application-start-of-global-aspx – feathj Jun 11 '13 at 12:34

1 Answers1

2

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
Sklivvz
  • 30,601
  • 24
  • 116
  • 172
  • Heya :) I was afraid you might suggest those *exact* two options, because that's *exactly* what i've been wracking my brain over, for the last hour :) [With the config suggestion looking like the best thing right now] – Pure.Krome Jun 11 '13 at 12:34