大家早,
我正在将 VS2010 与 VB 一起使用,并且试图在我的 Web 应用程序中进行 ping 测试。为了做到这一点并测试它是否有效,我简单地创建了一个按钮,当点击时应该 ping 指定的 IP 地址。
我相信按钮的代码应该可以正常工作。我唯一的问题是我的网页上出现以下错误消息......
System.NullReferenceException: Object reference not set to an instance of an object.
它在油菜线上出问题了...
Console.WriteLine("Address: {0}", vPingReply.Address)
我认为这是由于需要为 .Address 和 .Status 对象设置“属性”。我不太确定我是否正确添加了这些,因为我添加了一些属性,但是当我运行页面时我仍然遇到同样的问题?
有人可以看看和建议吗?
这是我的完整代码...
Imports Microsoft.VisualBasic
Imports System.Text
Imports System.Net.NetworkInformation
Imports System.Net.NetworkInformation.PingReply
Partial Class Ping
Inherits System.Web.UI.Page
Private mSend As PingReply
Private Property Send(p1 As String) As PingReply
Get
Return mSend
End Get
Set(value As PingReply)
mSend = value
End Set
End Property
Private mAddress As PingReply
Private Property Address(p2 As String) As PingReply
Get
Return mAddress
End Get
Set(value As PingReply)
mAddress = value
End Set
End Property
Private mStatus As PingReply
Private Property Status(p3 As String) As PingReply
Get
Return mStatus
End Get
Set(value As PingReply)
mStatus = value
End Set
End Property
Protected Sub btnPing_Click(sender As Object, e As System.EventArgs) Handles btnPing.Click
Dim vPing As New Ping
Dim vPingReply As PingReply = vPing.Send("xxx.xx.xxx.xx")
Console.WriteLine("Address: {0}", vPingReply.Address)
Console.WriteLine("Status: {0}", vPingReply.Status)
End Sub
End Class
任何帮助都是非常重要的。
贝蒂。