我创建了一个带窗口形式的网站,我只在远程页面中出现System.NullReferenceException
错误,如果我尝试用visual studio打开页面,在调试模式下,没有问题!为什么!?!?!?!
[NullReferenceException: Riferimento a un oggetto non impostato su un'istanza di oggetto.]
GeCo.DetaglioMilitare.Page_Load(Object sender, EventArgs e) in C:\Users\j972537\Documents\
Visual Studio 2010\Projects\GeCo\Admin\DettaglioMilitare.aspx.vb:45
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(
Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
这是带错误的代码:
Dim militare As New ldap.utente
militare = ldap.ldap_utente(matricola2)
Label7.Text = militare.grado
Label8.Text = militare.cognome
Label9.Text = militare.nome
Label10.Text = militare.codice_reparto
Label11.Text = militare.intestazione_reparto
Label12.Text = militare.email
这是我创建的类模块:
Public Class ldap
Public Class utente
Private _matricola As String = ""
Public Property matricola() As String
Get
Return _matricola
End Get
Set(ByVal val As String)
_matricola = val
End Set
End Property
Private _grado As String = ""
Public Property grado() As String
Get
Return _grado
End Get
Set(ByVal val As String)
_grado = val
End Set
End Property
Private _cognome As String = ""
Public Property cognome() As String
Get
Return _cognome
End Get
Set(ByVal val As String)
_cognome = val
End Set
End Property
Private _nome As String = ""
Public Property nome() As String
Get
Return _nome
End Get
Set(ByVal val As String)
_nome = val
End Set
End Property
Private _codice_reparto As String = ""
Public Property codice_reparto() As String
Get
Return _codice_reparto
End Get
Set(ByVal val As String)
_codice_reparto = val
End Set
End Property
Private _intestazione_reparto As String = ""
Public Property intestazione_reparto() As String
Get
Return _intestazione_reparto
End Get
Set(ByVal val As String)
_intestazione_reparto = val
End Set
End Property
Private _email As String = ""
Public Property email() As String
Get
Return _email
End Get
Set(ByVal val As String)
_email = val
End Set
End Property
End Class
' funzione per estrarre i dati relativi ad una matricola
Public Shared Function ldap_utente(matricola As String) As utente
Dim directory As DirectoryServices.DirectorySearcher
Dim result As DirectoryServices.SearchResult
Dim militare As utente = New utente
Try
directory = New DirectoryServices.DirectorySearcher("(cn=" & matricola & ")")
result = directory.FindOne
militare.matricola = matricola
militare.grado = result.Properties("title")(0).ToString
militare.cognome = result.Properties("sn")(0).ToString
militare.nome = result.Properties("givenname")(0).ToString
militare.codice_reparto = Left(result.Properties("physicaldeliveryofficename")(0).ToString, 5)
Dim lenght_string As Integer = result.Properties("description")(0).ToString.Length
militare.intestazione_reparto = Trim(Right(result.Properties("description")(0).ToString, lenght_string - 7))
militare.email = result.Properties("mail")(0).ToString()
Return militare
Catch ex As Exception
Return Nothing
End Try
End Function
答案 0 :(得分:1)
因为你没有包含DettaglioMilitare.aspx.vb:45
行的信息,所以我只能诊断可能发生的事情。
在wxception发生时,在函数ldap_utente
中,返回与Nothing
相同的Null
。因此,要调查代码中的错误,您有两种选择:
我几乎可以肯定您在连接到Active Directory时遇到问题,因为99%的页面安装为无法访问Active Directory的IIS用户。您可以尝试将应用程序池用户更改为域用户。