Solved

ASP.NET 4 and visual studio 2010 Membership web

Posted on 2011-02-16
6
542 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
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 create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

770 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