Solved

ASP.NET 4 and visual studio 2010 Membership web

Posted on 2011-02-16
6
546 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
[X]
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
  • 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

This collection of functions covers all the normal rounding methods of just about any numeric value.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

749 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