Request = HttpContext.Current.Request 未将对象引用设置对象的实例

SungCen 2009-03-28 09:48:53

Public Shared Function GetRealIP() As String

Dim Request As HttpRequest = HttpContext.Current.Request

If (String.IsNullOrEmpty(Request.ServerVariables("HTTP_VIA")) = False) Then
GetRealIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR").ToString()
Else
GetRealIP = Request.ServerVariables("REMOTE_ADDR").ToString()
End If

GetRealIP = ""
Return GetRealIP

End Function


请各位帮忙看下,我已经引用过了Imports System.Web

可就是一运行会报“未将对象引用设置对象的实例”这个错误,是什么原因啊??

求救~~我快疯掉了。~~~
...全文
464 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
knightwayne 2009-03-31
  • 打赏
  • 举报
回复
Dim Request As New HttpContext.Current.Request
最好不要用关键字.

xue1234567890 2009-03-31
  • 打赏
  • 举报
回复
[Quote=引用楼主 SungCen 的帖子:]
VB.NET code
Public Shared Function GetRealIP() As String

Dim Request As new HttpRequest = HttpContext.Current.Request

If (String.IsNullOrEmpty(Request.ServerVariables("HTTP_VIA")) = False) Then
GetRealIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR").ToString()
Else
GetRealIP = Request.ServerVariables("REMOTE_ADDR").ToString()
End…
[/Quote]
迈克揉索芙特 2009-03-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 net_lover 的回复:]
你是用在B/S结构的程序中的吗
[/Quote]

楼主用在winform了吧?
lqw521326 2009-03-30
  • 打赏
  • 举报
回复
没有实例化。加个new 在定义时
vwxyzh 2009-03-28
  • 打赏
  • 举报
回复
1、用了多线程了吧,HttpContext.Current在新开的线程(或者线程池的线程)里面是无法访问到的
2、或者根本不是Asp.net程序。。。
孟子E章 2009-03-28
  • 打赏
  • 举报
回复
你是用在B/S结构的程序中的吗
wuyq11 2009-03-28
  • 打赏
  • 举报
回复
Dim Request As New HttpContext.Current.Request
coodd 2009-03-28
  • 打赏
  • 举报
回复
把Shared去掉

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧