IIS 7模块可以在OnAuthenticateRequest挂钩或OnPostAuthenticateRequest挂钩中检索服务器吗?
“服务器”是指IIS验证的服务器(即使它是localhost,例如在Windows身份验证的情况下)
答案 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_NAME
或HTTP_HOST
代替。