OK、私はこのサイトだけでなく、役に立たない答えを探している他のサイトを精査しました。
新しいWebサイトには、すべてのメンバーがこの管理セクション内の特定のページにアクセスできるようにする管理セクションが付属しています。
ただし、すべてのページへのアクセスが許可されているのは3つだけです。
ログインページを使用して、関心のある項目のメニューを含む管理セクションにすべてのユーザーを表示しようとしています。
私たちの目標は、ユーザーがこのセクションにアクセスし、表示が許可されていないアイテムをクリックすると、ウェルカムページにリダイレクトされることです。
もちろん、「このページを表示する権限がありません」というメッセージの方が適切です。
このタスクを支援するために変更できるリンクまたはサンプルコードはありますか?
以下のコードは機能していません。
それは私を管理セクションにうまく誘導します。次に、すべてのリンクのpage_loadイベントで、セッションを使用してユーザーを制限しようとします。
例:if 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
どんな援助も大歓迎です。