限制基于IP地址的访问ELMAH [英] Restrict access to Elmah based on IP address

查看:332
本文介绍了限制基于IP地址的访问ELMAH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要限制访问elmah.axd。基于某些IP地址elvue.html。该网站是在IIS 6.0和.Net 3.5。我不能使用窗体身份验证或Windows身份验证。我想到的是使用HTTP模块的方法。
http://www.$c$cproject.com/Articles/16384/Using-ASP-NET-HTTP-Modules-to-restrict-access-by-I

I need to restrict access to elmah.axd. elvue.html based on certain IP addresses. The website is on IIS 6.0 and .Net 3.5. I cannot use Forms authentication or windows authentication. I am thinking of using the approach of an http module. http://www.codeproject.com/Articles/16384/Using-ASP-NET-HTTP-Modules-to-restrict-access-by-I

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

I cannot use the approach of restricting access in web.config since that is only for IIS 7. http://boseca.blogspot.com/2010/12/programmatically-addremove-ip-security.html

有人是否有我如何能解决这个问题的指针?请建议。

Does someone have pointers on how I can tackle this problem? Please advise.

推荐答案

我实现了这个使用以下code:

I implemented this using the following code:

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;
            }
        }

这篇关于限制基于IP地址的访问ELMAH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆