开发者

only allow certain ip range to asp.net page

in my asp c开发者_高级运维ode i was using

<%
UserIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If UserIPAddress = "" Then 
UserIPAddress = Request.ServerVariables("REMOTE_ADDR")
end if


IF Left(UserIPAddress,11) = "111.111.111" or Left(UserIPAddress,10) = "444.444.44"  then
%>

how could i do something like this in asp.net(using vb.net)


Something like this should work:

Dim userIPAddress As String =  Request.ServerVariables("HTTP_X_FORWARDED_FOR") 

If String.IsNullOrEmpty(userIPAddress) Then
    userIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If

If userIPAddress.StartsWith("111.111.111") Or userIPAddress.StartsWith("444.444.44") Then
  ' Do  something
End If

So you'll notice the Request object still exists and in this case works the same. Strings are now objects as well, so typically you wouldn't see any functions like Left. userIPAddress == "" should still work, though I put in String.IsNullOrEmpty().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜