开发者

using session state dont work properly

i am still new to using session state, i want to convert page name into and integer according to a database table a function then compares "X" and "Y" to check if a user have the right to view this page

i know this is not the best way of managing website security, but it is like "training on how to use the session"

what have i done wrong

Partial Class advancedsearch
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Try
        Label1.Text = Session("username").ToString

        Label3.Text = Session("role").ToString
        Label4.Text = System.IO.Path.GetFileName(Request.Url.ToString())


  开发者_StackOverflow中文版  Catch ex As Exception
        Response.Redirect("login.aspx")
    End Try

    If Label1.Text = "" Then
        Response.Redirect("login.aspx")

    End If
Dim x As Integer = Int32.Parse(Label3.Text)

    Dim y As Integer = Int32.Parse(DropDownList1.SelectedItem.ToString)

    If x < y Then Response.Redirect("login.aspx")


End Sub


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Response.Redirect("default.aspx")
End Sub
End Class


try putting the comparison part in pre render complete

Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete
    Dim x As Integer = Int32.Parse(Label3.Text)

    Dim y As Integer = Int32.Parse(DropDownList1.SelectedItem.ToString)

    If x < y Then Response.Redirect("login.aspx")

End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜