سؤال

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

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.

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top