首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

有个VB.net的如何转成asp.net

2012-01-19 
有个VB.net的怎么转成asp.net帮个忙谢谢!~~~~~useripRequest.ServerVariables( HTTP_X_FORWARDED_FOR )

有个VB.net的怎么转成asp.net
帮个忙谢谢
!~~~~~


userip   =   Request.ServerVariables( "HTTP_X_FORWARDED_FOR ")  
If   userip   =   " "   Then   userip   =   Request.ServerVariables( "REMOTE_ADDR ")  
......  

即:如果客户端通过代理服务器,则取   HTTP_X_FORWARDED_FOR   的值,如果没通过代理服务器,就取   REMOTE_ADDR   的值。  

'通用函数:如果不能取客户端真实IP,就会取客户端的代理IP  
Private   Function   getIP()  
Dim   strIPAddr  
If   Request.ServerVariables( "HTTP_X_FORWARDED_FOR ")   =   " "   OR   InStr(Request.ServerVariables( "HTTP_X_FORWARDED_FOR "),   "unknown ")   >   0   Then  
strIPAddr   =   Request.ServerVariables( "REMOTE_ADDR ")  
ElseIf   InStr(Request.ServerVariables( "HTTP_X_FORWARDED_FOR "),   ", ")   >   0   Then  
strIPAddr   =   Mid(Request.ServerVariables( "HTTP_X_FORWARDED_FOR "),   1,   InStr(Request.ServerVariables( "HTTP_X_FORWARDED_FOR "),   ", ")-1)  
ElseIf   InStr(Request.ServerVariables( "HTTP_X_FORWARDED_FOR "),   "; ")   >   0   Then  
strIPAddr   =   Mid(Request.ServerVariables( "HTTP_X_FORWARDED_FOR "),   1,   InStr(Request.ServerVariables( "HTTP_X_FORWARDED_FOR "),   "; ")-1)  
Else  
strIPAddr   =   Request.ServerVariables( "HTTP_X_FORWARDED_FOR ")  
End   If  
getIP   =   Trim(Mid(strIPAddr,   1,   30))  
End   Function  


[解决办法]
userip = Request.ServerVariables( "HTTP_X_FORWARDED_FOR ");
if (userip == " ") {
userip = Request.ServerVariables( "REMOTE_ADDR ");
}

热点排行