0

Can an IIS 7 module retrieve the server in an OnAuthenticateRequest hook or an OnPostAuthenticateRequest hook?

By "server" I mean the server that the IIS authenticated against (even if it's localhost, for example in the case of windows authentication)

polo
  • 1,352
  • 2
  • 16
  • 35

1 Answers1

2

In the method you add as the event delegate, you can do something like:

private void onAuthenticateRequest(object sender, EventArgs e) {
  var application = (HttpApplication) sender;
  HttpContext context = application.Context;

  string address = context.Request.ServerVariables["LOCAL_ADDR"];
}

This will give you IP address of the server currently serving the users request. If you want the servers name, then you could use either SERVER_NAME or HTTP_HOST instead.

Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117