|
1 | | -using System; |
| 1 | +using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Configuration; |
4 | 4 | using System.Linq; |
@@ -79,13 +79,49 @@ private void InitializeStatic() |
79 | 79 | } |
80 | 80 | } |
81 | 81 |
|
| 82 | + |
| 83 | + |
82 | 84 | private void context_AuthenticateRequest(object sender, EventArgs e) |
83 | 85 | { |
84 | 86 | var app = (HttpApplication)sender; |
85 | 87 |
|
86 | 88 | if (_ignoreIPAddresses != null) |
87 | 89 | { |
88 | | - var userHostAddress = app.Context.Request.UserHostAddress; |
| 90 | + |
| 91 | + |
| 92 | + /////////////////////////////////////////////////////////////////////////////////////// |
| 93 | + // Generic |
| 94 | + var userHostAddress = ""; |
| 95 | + // Check CF Connecting IP |
| 96 | + if (app.Context.Request.Headers["CF-CONNECTING-IP"] != null) |
| 97 | + { |
| 98 | + userHostAddress = app.Context.Request.Headers["CF-CONNECTING-IP"]; |
| 99 | + } |
| 100 | + else if (String.IsNullOrEmpty(userHostAddress) || userHostAddress.ToLower() == "unknown") |
| 101 | + { |
| 102 | + userHostAddress = app.Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; |
| 103 | + |
| 104 | + } |
| 105 | + else if (string.IsNullOrEmpty(userHostAddress) || userHostAddress.ToLower() == "unknown") |
| 106 | + { |
| 107 | + |
| 108 | + userHostAddress = app.Context.Request.UserHostAddress; |
| 109 | + } |
| 110 | + ////////////////////////////////////////////////////////////////////////////////////// |
| 111 | + // If using CF & Azure App Service |
| 112 | + //var userHostAddress = ""; |
| 113 | + //// Check CF Connecting IP |
| 114 | + //if (app.Context.Request.Headers["CF-CONNECTING-IP"] != null) |
| 115 | + //{ |
| 116 | + // userHostAddress = app.Context.Request.Headers["CF-CONNECTING-IP"]; |
| 117 | + //} |
| 118 | + //else if (string.IsNullOrEmpty(userHostAddress) || userHostAddress.ToLower() == "unknown") |
| 119 | + //{ |
| 120 | + |
| 121 | + // userHostAddress = app.Context.Request.UserHostAddress; |
| 122 | + //} |
| 123 | + ////////////////////////////////////////////////////////////////////////////////////// |
| 124 | + |
89 | 125 | if (!string.IsNullOrEmpty(userHostAddress) && _ignoreIPAddresses.Any(a => a.IsInRange(userHostAddress))) |
90 | 126 | return; |
91 | 127 | } |
|
0 commit comments