Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ASP.NET 4 and visual studio 2010 Membership web

Posted on 2011-02-16
6
545 Views
Last Modified: 2013-11-26
Hello.  i am new to ASP.net programmng.  I am using visual studio 2010 and created a website using asp.net 4 and vb.  The website installed the default login sceem and allows me to create roles.  What I want to have the registered user directed to a specific page built for them based on their user id.    Can anyone point me in the right direction to get this done.  So far I create roles for each user and allowed only the user assigned to the role access to the page i want them to go.   But everytime a user logs in it automatically directs them to the default.aspx page.

Thank you
0
Comment
Question by:bidgadget
  • 3
  • 3
6 Comments
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 34915293
Hi,

You have a couple of options:

1) In the Page_Load event (or Page_Init) for Default.aspx, add some logic for the conditional redicrection - or -
2) For the Login control, specify the "DestinationPageUrl" property to something like "Redirect.aspx" and put some code in there:
Partial Class Redirect
    Inherits System.Web.UI.Page


    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        If Not Page.IsPostBack Then
            If User.Identity.IsAuthenticated Then
                For Each role As String In Roles.GetAllRoles()
                    If User.IsInRole(role) Then
                        Response.Redirect("~/" & role.ToString() & ".aspx")
                        Exit For
                    End If
                Next
            End If
        End If
    End Sub
End Class

Open in new window


Assuming you have role names matching page names this little piece of code will automatically redirect the user to the correct page. Let's say you have a role called "admins" - if you have a page called "admins.aspx" any user in that group will be directed to it. You will need to change this logic to suit your needs but you should get the idea.

/Carl.
0
 

Author Comment

by:bidgadget
ID: 34915545
Thank you. Quick question and please forgive my lack of experience.  When you say in the login control, do you mean the login.aspx page.  And where do I specifily the destination URL.

Thank you for responding
0
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 500 total points
ID: 34915679
Hi,

In your login page (presumably Login.aspx) you will have a server control like:

<asp:Login ID="Login1" runat="Server">
</asp:Login>

Either you select the control in the IDE and scroll through the properties window until you find the "DestinationPageUrl" property or simply add the property to the declarative markup like:

<asp:Login ID="Login1" runat="Server" DestinationPageUrl="~/Redirect.aspx">
</asp:Login>

Please note, the declarative markup for your control might contain other properties other than what are shown here.

/Carl.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:bidgadget
ID: 34915883
Sorry.  One last question.  I was able t add the redirect.aspx  your explaination was perfect.  On the redirect.aspx I am not sure where to add the code

Partial Class Redirect
    Inherits System.Web.UI.Page


    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        If Not Page.IsPostBack Then
            If User.Identity.IsAuthenticated Then
                For Each role As String In Roles.GetAllRoles()
                    If User.IsInRole(role) Then
                        Response.Redirect("~/" & role.ToString() & ".aspx")
                        Exit For
                    End If
                Next
            End If
        End If
    End Sub
End Class
0
 

Author Comment

by:bidgadget
ID: 34916106
I found it.  works perfect.  thans a million
0
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 34916211
Hi,

You're welcome!

/Carl.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

809 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