IIS 7 模块能否在 OnAuthenticateRequest 挂钩或 OnPostAuthenticateRequest 挂钩中检索服务器?
“服务器”是指 IIS 对其进行身份验证的服务器(即使它是 localhost,例如在 Windows 身份验证的情况下)
IIS 7 模块能否在 OnAuthenticateRequest 挂钩或 OnPostAuthenticateRequest 挂钩中检索服务器?
“服务器”是指 IIS 对其进行身份验证的服务器(即使它是 localhost,例如在 Windows 身份验证的情况下)
在您添加为事件委托的方法中,您可以执行以下操作:
private void onAuthenticateRequest(object sender, EventArgs e) {
var application = (HttpApplication) sender;
HttpContext context = application.Context;
string address = context.Request.ServerVariables["LOCAL_ADDR"];
}
这将为您提供当前服务于用户请求的服务器的 IP 地址。如果您想要服务器名称,那么您可以使用SERVER_NAME
或HTTP_HOST
代替。