Solved

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

Posted on 2008-06-24
5
1,072 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
  • 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 500 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction (All good things must come to an end (http://en.wikipedia.org/wiki/All_Good_Things...)) The original MySQL API (http://php.net/manual/en/book.mysql.php) has gone away, deprecated by PHP in Version 5.5, and removed from PHP in all curre…
A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

757 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

20 Experts available now in Live!

Get 1:1 Help Now