好的,我已经搜索了这个网站以及其他寻找答案的网站,但都无济于事。
我们的新网站带有管理部分,允许所有成员访问此管理部分中的某些页面。
但是,只有 3 个可以访问所有页面。
我正在尝试使用登录页面通过感兴趣的项目菜单让所有用户进入管理部分。
我们的目标是,当用户进入此部分并单击他们无权查看的项目时,他们将被重定向回欢迎页面。
更好的选择当然是一条消息,“您无权查看此页面”。
是否有我可以修改的链接或示例代码来帮助我完成这项任务?
我下面的代码不起作用。
它引导我到管理部分就好了。然后在每个链接的 page_load 事件上,我会使用会话来尝试限制用户。
示例:如果 Session("Admin") <> True then response.Redirect("home.aspx") End If
但并不限制任何人查看屏幕上列出的任何链接。
Sub CmdLogin_Click(ByVal Sender As Object, ByVal E As EventArgs) Handles CmdLogin.Click
Dim StrUser As String, StrPass As String
Dim BValid As Boolean
Dim Conn As OleDbConnection
Dim Cmd As OleDbCommand
Dim rs As OleDbDataReader
Dim StrSQL As String
' We will request all variables from our form with this.
'Protect against SQL Injection
StrUser = Replace(txtUser.Text, "'", "''", 1, -1, 1)
StrPass = Replace(txtPass.Text, "'", "''", 1, -1, 1)
' This is our boolean variable for validation purposes set to true if valid user
BValid = False
' Initialize Database Connection
Conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("App_Data\Members.mdb"))
' Create Select Command
StrSQL = "SELECT Access_Level, myEmail,UserPassword FROM tblUsers WHERE myEmail='" & StrUser & "' AND UserPassword = '" & StrPass & "'"
'Response.Write(StrSQL)
'Response.End()
Cmd = New OleDbCommand(StrSQL, Conn)
Conn.Open()
rs = Cmd.ExecuteReader()
' This acts like the (Not RecordSource.Eof) in ASP 3.0
While rs.Read()
If rs("Access_Level") = "1" Or rs("Access_Level") = "2" Then
Session("Admin") = True
Response.Redirect("admin.aspx")
'Response.Write(StrPass)
'Response.End()
Dim redirectTo As String = Trim(Session("RedirectTo"))
BValid = True
Else
End If
End While
' Don't forget this
Conn.Close()
' This handles all response per validation
' If validated it goes to admin.aspx page
If BValid = True Then
Session("userid") = StrUser
Dim redirectTo As String = Trim(Session("RedirectTo"))
If redirectTo <> "" Then
Response.Redirect(redirectTo)
Else 'They just got in without trying to go to a restricted page
Response.Redirect("admin.aspx")
End If
ElseIf BValid = False Then
lblError.Text = "Login failed: Please try again."
End If
End Sub
非常感谢任何帮助。