Home page redirection

I have code in my ASP_ master page_Init page that checks if the user is allowed on the content page and if it does not redirect them to the login page. This code works great with the validation itself. However, I found that the contents of the Page_Load page still fires after the above redirect. This causes a problem on pages that assume that the user is logged in and certain variables are set.

This is the main page code (simplified)

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
...
            If Access_Level > User_Level_ID Then
                Response.Redirect("~/login.aspx", False)
            End If

    End Sub

The above test works fine, and the redirect line is executed, but does not take effect before the code below is launched and executed.

This is the content page code.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim Rec_IDs As New List(Of String)
    Rec_IDs = Session("Rec_IDs")
    lblCount.Text = String.Format("You have {0} records in your cart", CType(Rec_IDs.Count, String)) 'this gives an error if Session("Rec_IDs") is null
End Sub

, , , /, , .

- ? , , - .

.: -)

+3
2
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
...
            If Access_Level > User_Level_ID Then
                Response.Redirect("~/login.aspx", True)
            End If

    End Sub

Response.Redirect( "~/login.aspx", True) .

"Response.Redirect(" ~/login.aspx ", False)", . .

+5

, Response.Redirect false - , .

true, ( _ /s.) EDIT: , )

Response.Redirect("~/login.aspx", True)

, , ... . login.aspx , ...

+3

All Articles