亲爱的StackOverflow社区,
我仍然是ASP.NET的新手,玩游戏一直在玩,我在登录时遇到错误,它出现了一个错误,例如" Page重定向太多次"并且它发生了一些保持循环的东西,我无法在2天后弄明白。
我已经使用header.acsx实现了我的登录,因此它可以是对所有页面的全局身份验证。
这是head.vb的代码:
If String.IsNullOrEmpty(Session(GetSessionKey("UserName"))) Then
Dim userName As String = HttpContext.Current.User.Identity.Name.Split("\")(1)
SessionInitialiser(userName)
End If
Response.Redirect("~/EventRegistration.aspx")
Page_Load功能:
Dim adserv As New ActiveDirectory()
Dim userDetails As WebServiceUserPrincipal = adserv.Getuser(userName)
Dim userGroups As String() = adserv.GetUserGroups(userName)
Dim _dt As New DataTable
_dt.Columns.Add("Group")
For Each item As String In userGroups
Dim _row As DataRow = _dt.NewRow()
_row("Group") = item
_dt.Rows.Add(_row)
Next
Session(GetSessionKey("FullName")) = userDetails.DisplayName
Session(GetSessionKey("Groups")) = _dt
Session(GetSessionKey("UserName")) = userName
Session(GetSessionKey("Switch")) = "OK"
Dim filter_auditGroup As String = ConfigurationSettings.AppSettings("FILTER_GROUP")
Dim _adt As New DataTable
_adt.Columns.Add("Group")
For Each item As String In userGroups
If (item = filter_auditGroup) Then
Dim _row As DataRow = _adt.NewRow()
_row("Group") = item
_adt.Rows.Add(_row)
End If
Next
'If _adt.Rows.Count > 0 Then
' Session(GetSessionKey("AuditGroups")) = _adt
'End If
End Sub
检查访问功能
If Not IsPostBack Then
Dim arr As Array = Request.Url.AbsolutePath.Split("/")
Dim page As String = arr(arr.Length - 1).ToString().Split(".")(0) '-- Ballot.aspx, remove .aspx and get Ballot only
Dim signOut As New List(Of String)
signOut.Add("SwitchUser")
signOut.Add("SignOut")
If (Not signOut.Contains(page, StringComparer.OrdinalIgnoreCase)) Then
If (String.IsNullOrEmpty(Session(GetSessionKey("UserName")))) Then
Response.Redirect("~/Default.aspx")
Else
Dim group As DataTable = Session(GetSessionKey("Groups"))
'Dim auditGroup As DataTable = Session(GetSessionKey("AuditGroups"))
Dim adminPage As New List(Of String)
adminPage.Add("BallotProcess")
adminPage.Add("CodeTablePage")
adminPage.Add("MaintainBallotItem")
adminPage.Add("MaintainCodeItem")
adminPage.Add("MaintainItemDetail")
If (adminPage.Contains(page, StringComparer.OrdinalIgnoreCase) And Not CheckAdmin(group)) Then
Response.Redirect("~/EventRegistration.aspx")
End If
'If (page.Equals("AuditPage", StringComparison.OrdinalIgnoreCase) And Not CheckAudit(group)) Then
' Response.Redirect("~/default.aspx")
'End If
End If
End If
End If
检查管理员功能
Private Function CheckAdmin(ByVal group As DataTable) As Boolean
Dim i As Integer
If Not IsNothing(group) Then
For i = 0 To group.Rows.Count - 1
If group.Rows(i)(0) = ConfigurationSettings.AppSettings("FILTER_GROUP") Then
CheckAdmin = True
Session(GetSessionKey("EventAdmin")) = 1
Exit Function
End If
Next
End If
End Function
答案 0 :(得分:0)
我通过无数次调试找到了答案,我需要修复此代码只需将Response.Redirect("〜/ EventRegistration.aspx")移到上面的If Else语句中。这是因为当if else语句执行以获取标识时,在其if else语句之后该值将为Nothing,然后它将重定向到页面,而页面将尝试获取标识并且它将再次执行if else无数次..
If String.IsNullOrEmpty(Session(GetSessionKey("UserName"))) Then
Dim userName As String = HttpContext.Current.User.Identity.Name.Split("\")(1)
SessionInitialiser(userName)
的Response.Redirect("〜/ EventRegistration.aspx&#34) 结束如果