.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Redirecting based on roles c#

Posted By:      Posted Date: October 05, 2010    Points: 0   Category :ASP.Net

I'm trying to redirect users upon login based on their roles which were defined in the Administer website feature of asp.net.

Heres what I'm trying

    protected void Login1_LoggedIn(object sender, EventArgs e)
        // if there is no returnUrl in the query string , we redirect based on user role  
        if (string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
            // please don't use User.IsInR

View Complete Post

More Related Resource Links

Trying to get Roles to populate a checkboxlist based on tutorial and having issues.


I have been using the following tutorial and had to convert the code to C# for my project, now i cant get the code to work, im getting red line under the word "in" in the UpdateRolesFromList,
i tried to add a datasource on page load for the checkboxlist like so RoleList.DataSource = PopulateRoleList(User.Identity.Name.ToString());

and gives me error saying cannot implictly convert type 'void' to 'object'


What am i missing, that when i load the page or even do a search it never displays the checkbox list as it shows in the tutorial?

        protected void Page_Load(object sender, EventArgs e)

        public void PopulateRoleList(string userName)
            string[] roleNames = null;
            string roleName = null;
            roleNames = Roles.GetAllRoles();
            foreach (string roleName_loopVariable in roleNames)
                roleName = r

Redirect to specific page based on user Roles

I am using Formsauthentication. My situation is as per below:the login form has codebehind :==============================protected void LoginButton_Click(object sender, EventArgs e)        {            TextBox uname = Login1.FindControl("UserName") as TextBox;            TextBox pass = Login1.FindControl("Password") as TextBox;            CheckBox rm = Login1.FindControl("RememberMe") as CheckBox;            Literal fail = Login1.FindControl("Literal1") as Literal;            if (Membership.ValidateUser(uname.Text, pass.Text))            {                /                FormsAuthentication.SetAuthCookie(uname.Text, rm.Checked);                            }        &

redirecting different roles WITH password



Im trying to redirect different roles to different pages. Its working but the code I'm entering allows people through even with incorrect passwords. 

    protected void  Login1_Authenticate(object sender, AuthenticateEventArgs e)
                if (Roles.IsUserInRole(Login1.UserName, "Staff"))

Infopath view based on roles


hi, me again

i have created a form with 3 views.

what i'm trying to do is seperate the form in 3, for the user, approver and submitter to database.

first the user open the form to fill it in. then the approver opens the form to approve it, and at last the "submitter to database" open the form to send the records to the database.

for each view i created a role. when the user open the form it opens the form with the view for the user, and when the approver open the form it opens the form with the view for the approver.

but when the "submitter to the database" open the form it opens with the view of the approver.

how can i fix this so when the form is open by the "submitter to database" it opens with the view for the "submitter to database"?

redirect to specific web page based on roles


Is there a tutorial on how to redirect user to a specific web page based on his/her role?

For example, I have teacher role and student role. When the teachers login, it will redirect the teacher to the teacher web page and the students redirected to the student web page.


I want to send user to different pages based on their roles



I'm using the built-in membership controls and classes to manage authorization and authentication in my app.

Here's what I want to do:

If the user is in "Manager" role, I want to send him/her to the manager page no matter where he/she came from .

If the user is in "Supervisor" role, I want to send him/her to supervisor page no matter where he/she came from.

However, if the user is not in any role, just a registered member, I want to send him/her back to where he/she came from as stated in ReturnUrl. If no, ReturnUrl is specified, I will send him/her to the home page.

On my login page, I'm using the Login server control but in my code behind, there's no method wired to the control because the control takes care of everything.

I assume I need to add a method and wire it to the submit button, is that right? If so, I'll have to really handle the login event which means I'll need more info about how to do that. So I'd appreciate some pointers in how to do that. Thanks.

Client based InfoPath form User Roles: Order of Evaluation?

Again, client based (and no, this is a separate question from my other one, figured I'd ask them as separate threads).

To keep the example simple, let's assume I have 3 roles:  Administrator; Supervisor; Everyone.

Administrator is determined by your membership in a domain group, and this works great.  It's at the top of the list, so (according to MS), if it is evaluated that I'm in this role, execution stops, and that's my role.

Supervisor is determined if your name is in the 'Supervisor' field on the form (this works as well, even though my other post indicates it doesn't, but it doesn't in the context I'm using it there, so we'll move on and assume it works here).

Everyone else.

Now, if you are in the domain that evaluates to Administrator, that works great, until someone puts your name in the Supervisor field, then you evaluate to Supervisor.  This is wrong.  According to MS, it should still be evaluating Administrator first, and that is my role.  One of two things is happening:

1. MS is wrong, and it evaluates everything (I don't think this is the case, as I've tried changing the order of evaluation, and it still comes up Supervisor if my name is in that field, even though I'd normally come up as Administrator, based on my domain membership).

2. It evaluates i

5 GridView Themes Based on Google's Personalized Homepage (igoogle)

One of the silly features I have found that I like about igoogle is how the pages color palette changes depending upon the time of day. So as the day progresses from morning to afternoon to evening the colors on the page change as well. Like I said, I know this is a silly feature, but I like it. And I have asked around a little bit and seems like other people like it to. To get a better idea of how the colors change, here are the background images from a few of the HTML elements.

ASP.NET forms authentication with roles

.A timeout is specified in minutes. This is "time since last request" not the "time since login". If a login is indicated to be persistent (described later) this is ignored.
.A protection method is specified for the cookie.
Next I wanted to specify a folder to which access is restricted to people who have logged in. To do this I entered the following code in the web.config file (beneath

dynamically adding sql server columns based on number of files in fileuploader


I want to create a new table to sql database at runtime.  The column names would be "Name", "Date", "Event".  I would also like to have one more column name "Image" but the problem is that since the amount of images will vary, I want the application to count the amount of files in the Multiple fileuploader and then add a image column to the table for the respected amount of files. 

For example if i am uploading 3 files in the multiple fileuploader, the names should be "Name", "Date", "Event", "Image1", "image2", Image3"

I also would like that table name to be name dynamically from the textbox Name when the user enters the information.


I have the following code to make a new table, but I dont know how to name the fields at runtime like previously asked please help!!!


Dim objConn As New SqlConnection("Server=<servername>;uid=<userid>;pwd=<password>;database=master")


Unique content within master page based on conditions met


 Hi all-

I would like to present users with unique content based on certain conditions being met as they land on the home page (default.aspx).  The condition logic will be in the VB code behind Page Load event. The content will go in a content placeholder as specificed from the master page. 

However, the content change wouldn't be something small (ie making a panel or label visible or not) but rather it will be different HTML,  Divs and databound gridview content.  The HTML content will be stored in the database.

Can someone point me in the right direction for best practices on how to accomplish this?


Need help redirecting users to personalized page


 Hi, first timer here so be gentle.


I've been able to create a cool little website, it's up and running with users logging in and out, I created roles so my administrative team can see sensitive data that's not available to regular and anonymous users.

Now they would like me to create a page specific to each user.  For instance when user A logs in they are redirected to a page that has information that pertains to user A only (like a list of their benefits/ their remaining vacation time). This page needs to be accessible only to user A. 

I've watched a ton of the videos but have yet to see one that covers this topic, any help would be great!!!





Problem making Role based Menu in MVC application



 I want to make Rolebase menu in MVC such that if user doesnot have permission for some action then that Action name shouldnot be shown in the Menu.

 I have used the code in the url(http://forums.asp.net/t/1566328.aspx) in my MVC application.My application is a Discussion Forum(in MVC) same functionality as in this forum forums.asp.net

 I have used Controllers for post, thread etc.In each controller there are some actions that are using [Authorize(Roles)] attribute

 but this coding does not count  those Actions in Controllers having Authorize attribute according to the url http://forums.asp.net/t/1566328.aspx 

 In the code, Authorize attribute is applied to Controller class, but my requirement is of Applying Authorize attribute to some actions in controller so that some are available for all users and  some links are available rolewise.Now what is the solution for that?



Hard Code Roles on the Pages


If i hard coded role=Manager on the specific SiteMap/Folder/Page/etc. I will have problem when the manager need to remove from access a specific page. I need to change the code ont eh page/SiteMap/Folder more move the file into another folder.

What i have in mind is to change the role to taks oriented. such as role=AddStock, Edit Stock, Delete Stock, Print DO, Add Sales, Edit Sales, Deleted Sales..... (but it will be many role for 1 user compare to just 1 as Manager)

Will this cause performance issues later when each user have 60 roles and if i have 20,000 user will it affect the application performance?

Otherwise any other option? to make it flexible.

How to get data from table based on four table



I need to know how to show top 30 records from four table

with fastest speed.. in ms sql server 2005..

hope You do the needfull


how to bind Dropdownlist based on textbox values



I have one drodownlist which show data based om textbox values...

Let us consider i have 

Select Name from table1 where Type IN(@typ)

here @typ is textbox values

here for example textbox will have some thing like this L1,L2,L3..

How to filter Name based and shown in drodownlist based on this L1,L2,L3(on textbox)..

Help me in this

services based architecture


was giving a though on using ajax enabled wcf services as part of architecture

generally wht im using

is UI-> BL-> data access


is it suggestable to use wcf services layer instead

of BL

nd hv UI-> services-> data access

related to asp.net


would like to no pro's and con's of doing this thing.

is it suggestable to do it. 

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend