Solved

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

Posted on 2011-02-17
10
417 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:bidgadget
  • 6
  • 4
10 Comments
 
LVL 3

Expert Comment

by:jmro20
ID: 34916624
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
 

Author Comment

by:bidgadget
ID: 34916705
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
 
LVL 3

Expert Comment

by:jmro20
ID: 34916821
try this: Session.Item("LoginName")
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:bidgadget
ID: 34916917
Thanks again for your response. It still brings me to default2 instead of rick.asp
0
 
LVL 3

Expert Comment

by:jmro20
ID: 34917380
Instead of session try this: User.Identity.Name
0
 

Author Comment

by:bidgadget
ID: 34917493
Still not finding it.  My guess is I need to do something on page load?  but i am not sure what
0
 
LVL 3

Expert Comment

by:jmro20
ID: 34919127
When the user clicks the Login button ara you storing the username anywhere?
0
 
LVL 3

Expert Comment

by:jmro20
ID: 34919216
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
 

Author Comment

by:bidgadget
ID: 34919403
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
 
LVL 3

Accepted Solution

by:
jmro20 earned 500 total points
ID: 34919644
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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET 2013-How to validate a textbox and set focus to next control if true? 4 33
VB 2005 Tooltips on Form Load Event 15 29
mail.To.Add 5 24
Linq asp.net mvc 13 6
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now