如何在IIS 7模块OnAuthenticateRequest挂钩中获取服务器地址?

时间:2010-11-23 19:03:29

标签: asp.net iis iis-7 ihttpmodule

IIS 7模块可以在OnAuthenticateRequest挂钩或OnPostAuthenticateRequest挂钩中检索服务器吗?

“服务器”是指IIS验证的服务器(即使它是localhost,例如在Windows身份验证的情况下)

1 个答案:

答案 0 :(得分:2)

在您添加为事件委托的方法中,您可以执行以下操作:

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

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

这将为您提供当前为用户请求提供服务的服务器的IP地址。如果您想要服务器名称,那么您可以使用SERVER_NAMEHTTP_HOST代替。