How to specify destinationpageurl based on roll?

HelloExperts.

I have a web form application with a login control, ID=Login1.  I have three roles: admin, manager, and representative.

When logging in, admin and representative users need to be directed to CPC/frm2.aspx.  Representative users need to be directed to Member/frm3.aspx.  Members without a specified role need to be directed to Default.aspx.  

I have looked at numerous articles and have not been successful. Any help would be greatly appreciated.

Thanks,
J
ferguson_jeraldAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CamilliaCommented:
I do something similar in  onloggedIn  event

 protected void login_onloggedIn(object sender, EventArgs e)
    {


    
            if (Roles.IsUserInRole(Login1.UserName, "Admin")
                Login1.DestinationPageUrl = "~/main/profile/InitialSignup.aspx?pageTitleId=50";
            else if (firstTime == "1" &&
                     (Roles.IsUserInRole(Login1.UserName, "Staff") || Roles.IsUserInRole(Login1.UserName, "Admin")))
                Login1.DestinationPageUrl = "~/main/UserAccess/ChangePassword.aspx?pageTitleId=35&FirstTime=Y";
       
      

    }

Open in new window

ferguson_jeraldAuthor Commented:
Thanks for the reply, but I must be missing something. I don't have Roles as an option when I try to write the if statement.  Any idea on what I'm missing?
CamilliaCommented:
Post your code
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

ferguson_jeraldAuthor Commented:
Camilla - thanks for the assistance.  I was missing "using System.Web.Security;".  I can use Roles now.  I tried to use the code you provided but I get an error for "firstTime".  The error message is:
The name 'firstTime' does not exist in the current context
.

I tried this version of what I received from you but everybody gets redirected to Default.aspx:
protected void login_onloggedIn(object sender, EventArgs e)
        {   
            if (Roles.IsUserInRole(Login1.UserName, "Admin") || (Roles.IsUserInRole(Login1.UserName, "Representative"))
                Login1.DestinationPageUrl = "~/CPC-Admin/frm_twia_fnol_queue.aspx";
            else if (firstTime == "1" &&
                 Roles.IsUserInRole(Login1.UserName, "Representative"))
                   Login1.DestinationPageUrl = "~/MemberPages/frm_current_user_twia_fnol_queue.aspx";
        }

Open in new window


I also tried this, but all roles are still redirected to Default.aspx:
protected void Login1_OnLoggedIn(object sender, EventArgs e)
        {                        
            if(Roles.IsUserInRole(Login1.UserName, "Admin") || Roles.IsUserInRole(Login1.UserName, "Manager"))
            {
                Login1.DestinationPageUrl=("~/CPC-Admin/frm_twia_fnol_queue.aspx");
            }
            else if (Roles.IsUserInRole(Login1.UserName, "Representative"))
            {
                Login1.DestinationPageUrl = ("~/MemberPages/frm_current_user_twia_fnol_queue.aspx");
            }
            else
            {
                Login1.DestinationPageUrl = ("Default.aspx");
            }
        }

Open in new window


Thanks for the help.
ferguson_jeraldAuthor Commented:
A note - when I remove firstTime == "1" && from my version of the code you provided everybody still gets redirected to Default.aspx.  My apologies for not being clear initially.
CamilliaCommented:
Yeah, that was a sample from my code.

So it goes here
Login1.DestinationPageUrl = ("Default.aspx");

Open in new window


Have you stepped thru the code? what role do you see for the logged in user?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ferguson_jeraldAuthor Commented:
Camillia,

I reapply appreciate the help.

I stepped through the code and the current user was Admin as expected.

I tested with two different user accounts, Admin and a Manager.  Both are redirected to the Default page. I tested to be sure, and the Admin couldn't open Manager-only pages and the Manager couldn't open Admin-only pages.  At least now I know that the users are being identified by their roles correctly with regards to permissions.

Any other ideas?

Thanks,
J
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.