Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Page redirect baste on membership role. (asp.net 2.0 and c#)

Posted on 2008-06-24
5
Medium Priority
?
1,082 Views
Last Modified: 2013-12-16
I have 2 member ship roles in my site, directors and staff.  After a user logs in, I would like to have a page load event, that would redirect the directors to a different  start page.  Can someone show me how i can do this with a simple if statement, in the page load event?  Im working with ASP.Net 2.0 and C#.

Thanks for any help.
0
Comment
Question by:bmanmike39
[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
  • 2
  • 2
5 Comments
 
LVL 18

Expert Comment

by:philipjonathan
ID: 21856180
Does this help:
Response.Redirect("http://your_url_here");
0
 

Author Comment

by:bmanmike39
ID: 21856287
I understand the response redirect,  I dont know how to write the code, for the user.name.identity. in other words,

If  userneme = = directors
{
response.redirect(this url)
}

Something like the above.
0
 
LVL 18

Expert Comment

by:philipjonathan
ID: 21856439
Hi, do you mean how to check if the membership role equals certain value? It depends on what data type do you use to store the membership roles. Typically you would use integer, then the code would be like:

if (membershipRole == 0)  // let's say director
  Response.Redirect(... /* director page */);


otherwise, if it is a string:
if (membershipRole.Equals("Director"))
  Response.Redirect(... /* director page */);

The value of membershipRole should be stored somewhere in database, eg:

user_id | login_name | password | membership_role
------------------------------------------------------------------
1           | abc              | abc123     | 0
2           | def              | def123      | 1
...

You need to use select query to get that based on the login name the user supplied
0
 

Author Comment

by:bmanmike39
ID: 21856676
Im using the Asp.net 2.0 membership provider, and i have the roles turned on.  I need to get the role of the user from the provider. After the login page redirects to the start page.

I know how to get the users name for the provider, it User.Identity.Name but how do i get the users Role from the provider?
0
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 2000 total points
ID: 21865174
Hi,

I'm really a VB guy but I will give it a go in C# as well, please see the attached code snippets..

/Carl.
'VB.NET Version
 
Protected Sub Page_Load(ByVal sender as Object, ByVal e As System.EventArgs) Handles Me.Load
	If User.Identity.IsAuthenticated Then
		If User.IsInRole("directors") Then
			Response.Redirect("~/secure_directors/Default.aspx") 'Your url by choice..
		End If
		If User.IsInRole("staff") Then
			Response.Redirect("~/secure_staff/Default.aspx")
		End If
	End If
End Sub
 
'C# Version
 
protected void Page_Load(object sender, System.EventArgs e) {
    if (User.Identity.IsAuthenticated) {
        if (User.IsInRole("directors")) {
            Response.Redirect("~/secure_directors/Default.aspx"); //Your url by choice..
        }
        if (User.IsInRole("staff")) {
            Response.Redirect("~/secure_staff/Default.aspx");
        }
    }
}

Open in new window

0

Featured Post

Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

Question has a verified solution.

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

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

670 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