2013-02-20 69 views
3

我需要限制对elmah.axd的访问。基于特定IP地址的elvue.html。该网站在IIS 6.0和.Net 3.5上。我无法使用表单身份验证或Windows身份验证。我正在考虑使用http模块的方法。 http://www.codeproject.com/Articles/16384/Using-ASP-NET-HTTP-Modules-to-restrict-access-by-I根据IP地址限制对Elmah的访问

我不能使用在web.config中限制访问,因为这是仅适用于IIS 7 http://boseca.blogspot.com/2010/12/programmatically-addremove-ip-security.html

是否有人有我如何能解决这个问题指针的方法吗?请指教。

回答

3

我实现了这个使用下面的代码:

protected void Application_BeginRequest(Object sender, EventArgs e) 
     { 
      var ClientSourceIP = Context.Request.Headers["CLIENT_SRC_IP"]; 
      var HTTPClientSourceIP = Context.Request.Headers["HTTP_CLIENT_SRC_IP"]; 
      var isValidClientSourceIP = ClientSourceIP == null || 
       Regex.IsMatch(ClientSourceIP, ConfigurationManager.AppSettings["ValidClientSourceIP"]); 
      var isValidHTTPClientSourceIP = HTTPClientSourceIP == null || 
       Regex.IsMatch(HTTPClientSourceIP, ConfigurationManager.AppSettings["ValidHTTPClientSourceIP"]); 

      if (
       (Context.Request.Path.Contains("elmah.axd") || Context.Request.Path.Contains("elvue.aspx")) && 
       ((isValidClientSourceIP && isValidHTTPClientSourceIP) == false) 
      ) 
      { 
       this.Context.Response.StatusCode = 403; 
       return; 
      } 
     } 
0
+0

这两条建议不会为我工作,因为我不能使用任何形式\ windows身份验证。另外,elmah.axd文件不是实际的物理文件,因此第一个建议不起作用。 – 2013-02-21 03:56:04

+0

我很困惑,我无法看到任何引用Windows身份验证的IIS 6指南。您是否考虑过使用应用程序的身份验证系统来控制对这些文件的访问? – RandomUs1r 2013-02-21 16:46:16

相关问题