training video problem....

Last post 02-21-2007 10:13 PM by koure. 2 replies.

Sort Posts:

  • training video problem....

    11-02-2006, 11:01 AM
    • Loading...
    • dbrook007
    • Joined on 10-30-2006, 8:59 PM
    • Posts 38
    Hi.

    I have just been working through the ASP.Net 2.0 training video (Bob tabor : number 09 - Securing your Website with Membership and Login Controls) and have come across a problem.

    In the demo, towards the end, it shows you how to check that a user is a member of a Role.  The code used is: -

    Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If User.Identity.IsAuthenticated = False Then
            Server.Transfer("login.aspx")
        End If
        If Roles.IsUserInRole("Basic User") = False Then
            Server.Transfer("unauthorized.aspx")
        End If

    End Sub
    In the demo, the trainer goes to the page called SecurePage.aspx and enters a username that is valid but that he knows is NOT a member of the Role "Basic User".  He is then redirected as per the code above to unauthorized.aspx.
    On the unauthorized.aspx form, there is a LoginStatus control.  When he is testing the demo, he clicks the LoginStatus control - which is currently on "Logout".  The page is refreshed and the Logout is replaced with a "Login".
    He clicks on this, the Login control appears (the address in the address bar is http://localhost:1489/Lesson09/login.aspx?ReturnUrl=%2funauthorized.aspx). 
    He then enters a username that he know IS a member of the "Basic User" Role.  This time when he click Log in, he gets redirected to the Secure page - which is correct.
    However, when I attempt that last step, I get sent back to the unauthorized page.
    I've checked the obvious things - like that the user was actually in the Role etc.
    However, I just cannot get this to work.
    I am new to ASP.Net and so I don't really know where to start to look for what the problem is?
    I have gone through the training video twice now and I still get the same problem.  I have also downloaded the code from the asp.net website (url = http://www.asp.net/learn/videos/default.aspx?tabid=63) and I still get the same problem.
    Could it be some setting or something on my machine causing this problem?
    For info, I am using: -
    - Visual Studio .Net 2005 (Professional) (up to date)
    - Latest .Net installed
    - Windows XP Pro
    - Internet Explorer 6 (version 6.0.2900.2180.xpsp_sp2_gdr.050301-1519) SP2
    Obviously, if it works in the video, it should work on my PC.  It does not and I really need to know why and what the problem is.
    Any help appreciated.
    Kind regards
    Darren Brook
    Darren Brook
    e: darrenbrook@btconnect.com
  • Re: training video problem....

    02-21-2007, 10:10 PM
    • Loading...
    • koure
    • Joined on 11-07-2006, 12:40 PM
    • Posts 69

    I'm a newbie too in asp.net 2 

    try to use this code

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load     ----------------> try to change Sub form1_Load(etc...)   to   Sub Page_Load(etc...)
            If User.Identity.IsAuthenticated = False Then
                Server.Transfer("Login.aspx")
            End If

            If Roles.IsUserInRole("Basic User") = False Then     ----------------> here when you type in IsUserInRole after parenthesis scroll down for option number 2 where you have to type in only (userrole
                Server.Transfer("Unauthorized.aspx")                                     asstring) and not (username as string, userrole as string)
            End If
        End Sub

     

    hope it helped you 

  • Re: training video problem....

    02-21-2007, 10:13 PM
    • Loading...
    • koure
    • Joined on 11-07-2006, 12:40 PM
    • Posts 69

    sorry here is a better version

     

        'try to change Sub form1_Load(etc...)   to   Sub Page_Load(etc...)       
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If User.Identity.IsAuthenticated = False Then
                Server.Transfer("Login.aspx")
            End If

           'here when you type in IsUserInRole after parenthesis scroll down for option number 2 where you have to type in only     
            '(userrole as string) and not (username as string, userrole as string)
            If Roles.IsUserInRole("Basic User") = False Then
                Server.Transfer("Unauthorized.aspx")
            End If
        End Sub

Page 1 of 1 (3 items)
Microsoft Communities
Page view counter