vb.net之aspx获取请求参数内容值


  ''' <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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值