ASP.NET 4 WITH VISUAL BAIC Membership Web. Hyperlink or Button redirection

Simple question.  I have a ASP.NET 4 membership with visual basic.   When my users are authenicated I have them directed to default.aspx

I need a simple hyperlink or button on that when clicked or selected it will redirect them to a different page based on their
username.  Can some pleae let me know what I am doing wrong.  I am not sure what value to use to check who is logged in.

My code is attached
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Session("LoginName") = "Rick" Then
            Response.Redirect("Rick.aspx")

        Else
            Response.Redirect("default2.aspx")
        End If
    End Sub

Open in new window

bidgadgetAsked:
Who is Participating?
 
jmro20Connect With a Mentor Commented:
You are welcome. If the question has been answerd please don't forget to marked it as answered.

Hope you can get it all done.
0
 
jmro20Commented:
I think you are missing ~/ . Try this:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Session("LoginName") = "Rick" Then
            Response.Redirect("~/Rick.aspx")

        Else
            Response.Redirect("~/default2.aspx")
        End If
    End Sub

Open in new window

0
 
bidgadgetAuthor Commented:
Thank you for responding. I tried and I still am just getting forward to default2

Am I correct with the Session("LoginName") part.  I am not if I am correctly capturing the userid
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
jmro20Commented:
try this: Session.Item("LoginName")
0
 
bidgadgetAuthor Commented:
Thanks again for your response. It still brings me to default2 instead of rick.asp
0
 
jmro20Commented:
Instead of session try this: User.Identity.Name
0
 
bidgadgetAuthor Commented:
Still not finding it.  My guess is I need to do something on page load?  but i am not sure what
0
 
jmro20Commented:
When the user clicks the Login button ara you storing the username anywhere?
0
 
jmro20Commented:
If you are using Membership then I assume you are using the Login Control. Then you can do this in your loggin page:
Protected Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoggedIn
        If Membership.ValidateUser(Login1.UserName, Login1.Password) Then
            If Login1.UserName = "Rick" Then
                Response.Redirect("~/Rick.aspx")
            Else
                Response.Redirect("~/default2.aspx")
            End If
        End If

    End Sub

Open in new window

0
 
bidgadgetAuthor Commented:
i see how that would work thank you.  although I need the user to see the url directed to by the login page  I am trying to create a link once in the main page that would direct the users to a webfolder where there items are contained.

thanks again
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.