首先,如果我错误地或不完全遵守规则,我道歉。这是我的第一篇文章。
有人可以帮助解决我的问题。
我有一个功能齐全的Web应用程序并授权用户。
我的问题是我想在网站加载时添加一个检查,以查看PC当前是否已连接到工作网络。例如。当在家里并且没有通过VPN连接时,我想重定向到一个错误页面,说明没有连接到AD域网络。
目前该应用程序崩溃,但“无法访问ldap服务器”除外。
我希望这是有道理的。
已添加代码
Imports Microsoft.VisualBasic
Imports System.Security.Principal
Imports System.DirectoryServices
Imports System.DirectoryServices.AccountManagement
Imports System.Configuration.ConfigurationManager
Public Class Gen
Dim DomUser As System.DirectoryServices.AccountManagement.UserPrincipal = System.DirectoryServices.AccountManagement.UserPrincipal.Current
Public ADUser As String = AppSettings("DomainPrefix").ToString & DomUser.SamAccountName
Public ADEmail As String = DomUser.EmailAddress
Public ADForname As String = DomUser.GivenName
Public ADSurname As String = DomUser.Surname
Public ADFullName As String = ADForname & " " & ADSurname
Public wi As WindowsIdentity = HttpContext.Current.User.Identity
End Class
罪魁祸首是
Dim DomUser As System.DirectoryServices.AccountManagement.UserPrincipal = System.DirectoryServices.AccountManagement.UserPrincipal.Current
答案 0 :(得分:0)
最好的方法是使用适当的OOP范例。
Public Function CheckLDAP() As Boolean
Dim DomUser As System.DirectoryServices.AccountManagement.UserPrincipal
Dim blnLDAPOk As Boolean = False
Try
DomUser = System.DirectoryServices.AccountManagement.UserPrincipal.Current
blnLDAPOk = True
Catch ex as Exception
' Perhaps Throw an exception to be handled
End Try
Return blnLDAPOk
End Function
从类Gen
中,实例化类
Dim gLDAP = New Gen
If (gLDAP.CheckLDAP()) Then
' We are in
Else
' Whoops, no LDAP found
End If