Skip to content

Commit a28dbf5

Browse files
authored
Merge pull request nabehiro#18 from vijayraavi/master
Included CF check and all possible scenarios
2 parents 823239b + 5ad817e commit a28dbf5

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

HttpAuthModule/HttpAuthModule.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Configuration;
44
using System.Linq;
@@ -79,13 +79,49 @@ private void InitializeStatic()
7979
}
8080
}
8181

82+
83+
8284
private void context_AuthenticateRequest(object sender, EventArgs e)
8385
{
8486
var app = (HttpApplication)sender;
8587

8688
if (_ignoreIPAddresses != null)
8789
{
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+
89125
if (!string.IsNullOrEmpty(userHostAddress) && _ignoreIPAddresses.Any(a => a.IsInRange(userHostAddress)))
90126
return;
91127
}

0 commit comments

Comments
 (0)