Solved

ASP.NET 4 and visual studio 2010 Membership web

Posted on 2011-02-16
6
537 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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 …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

746 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

11 Experts available now in Live!

Get 1:1 Help Now