''' <summary>
''' 获取Cookies值
''' </summary>
Function GetCookies(ByVal ID As String, Optional ByVal Len As Integer = 8) As String
With HttpContext.Current.Request
If .Cookies(ID) Is Nothing Then Return "" '找不到此项
Dim temp As String = .Cookies(ID).Value.Trim '处理获取值
If temp.Length <= Len OrElse Len <= 0 Then Return temp
Return temp.Substring(0, Len)
End With
End Function
''' <summary>
''' 获取GET或POST值
''' </summary>
Function GetRequest(ByVal ID As String, Optional ByVal Len As Integer = 0, Optional NoDec As Integer = 0) As String
With HttpContext.Current
Dim temp As String = ""
If .Request.Form(ID) IsNot Nothing Then '找不到此项
temp = HttpUtility.HtmlDecode(.Request.Form(ID))
If NoDec = 1 Then temp = .Request.Form(ID)
ElseIf .Request.QueryString(ID) IsNot Nothing Then '找不到此项
temp = HttpUtility.UrlDecode(.Request.QueryString(ID))
If NoDec = 1 Then temp = .Request.QueryString(ID)
End If
If Len = 0 OrElse temp.Length <= Len Then Return temp
Return temp.Substring(0, Len)
End With
End Function
''' <summary>
''' 获取Session值
''' </summary>
Function GetSession(ByVal ID As String, Optional ByVal Len As Integer = 50) As String
With HttpContext.Current
If .Session Is Nothing OrElse .Session(ID) Is Nothing Then Return "" '找不到此项
If .Session(ID).Length <= Len OrElse Len <= 0 Then Return .Session(ID).Trim
Return .Session(ID).Substring(0, Len).Trim
End With
End Function
''' <summary>
''' 获取访问IP
''' </summary>
Function GetIp() As String
With HttpContext.Current.Request
Dim temp As String = ""
If .ServerVariables("HTTP_X_FORWARDED_FOR") IsNot Nothing Then temp = .ServerVariables("HTTP_X_FORWARDED_FOR").Trim '方法一
If temp = "" Then temp = .ServerVariables("REMOTE_ADDR").Trim '方法二
If temp = "" Then temp = .UserHostAddress.Trim '方法三
If temp.Split(",").Length > 1 Then temp = temp.Split(",")(0) '多个IP处理一下
Dim IPv() As String = temp.Split(".")
If IPv.Length = 4 AndAlso IPv(0) > 0 AndAlso IPv(0) < 256 AndAlso IPv(1) >= 0 AndAlso IPv(1) < 256 AndAlso IPv(2) >= 0 AndAlso IPv(2) < 256 AndAlso IPv(3) >= 0 AndAlso IPv(3) < 256 Then Return temp
Return ""
End With
End Function
08-27
100
02-02
1028