redirect to a different page after login page by checking IsInRole("")??

Hi,

I am using the form authentication and built in login page and Roles.
Say I have two roles, admin and user.
admin can access all of the pages but user can access one or two pages.
When the user logins, either he reaches the allowed page if he started with that link but he will be prompted for a login page if he started from restricted page.

I want to redirect that user who has the user Role to the alllowed pages every time.

Since I am using the built in login page, where can I check the IsInRole() so I can direct that user to only allowed pages.

From the login.aspx page has LoggedIn event, but when I code this. It still didn't authenticated user yet.

LoggedIn () {
if (User.IsInRole("User")) {

}....
}

How can I redirect users who are authenticated from the login page according to their Role??
Thanks.
dkim18Asked:
Who is Participating?
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.

ahllCommented:
Hi,

You can have the DestinationPageUrl set to a unique page for every roll. Once there you can redirect the browser to wherever you want depending on the Role
0
dkim18Author Commented:
OK.
How do I use that with my default LOGIN.aspx?

I am trying to direct them to different page according to the ROLE even if they are accessed from restricted pages and what not.
0
dkim18Author Commented:
One more thing, I am not manually authenticating users right now.

Does it require me to authenticate users manually??
Is there a way to do it without taking care of the authentication manually?
Thanks.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

ahllCommented:
You do not have to authenticate it manually. See bellow the code for the LoginForm.

The DestinationPageUrl="~/menu.aspx" property sets the page wneh they will be redirected when the login is successfull.
Now, on that Page_Load event you can have somethin like:

if User.IsInRole("Role1")
{
response.redirtect("page1.aspx")
}
else
{
response.redirect("page2.aspx")
}



                            <asp:Login ID="LoginForm" runat="server" BackColor="#F7F7DE" BorderColor="#A55129" BorderStyle="Solid"
                                BorderWidth="1px" Font-Names="Verdana" Font-Size="10pt" 
                                DisplayRememberMe="False" 
                                DestinationPageUrl="~/menu.aspx"
                                FailureText = "Wrong credentials">
                                <TitleTextStyle BackColor="#b72025" Font-Bold="True" ForeColor="White" />
                            </asp:Login> 

Open in new window

0
dkim18Author Commented:
I am assuming you are doing this in login page, correct??
if User.IsInRole("Role1")
{
response.redirtect("page1.aspx")
}
else
{
response.redirect("page2.aspx")
}

For some reason, you can not access anything from User. It comes out as NULL.
I even tried it with the login's textbox, Login1.Text...still null.
0
dkim18Author Commented:
I found something online.
I need to try it tomorrow.



http://forums.asp.net/p/1095499/1667817.aspx
 public void Login1_LoggedIn(object sender, EventArgs e)
    {
        //Login loginControl = LoginView1.Controls[0].FindControl("Login1") as Login;
        string txtUsername = ((System.Web.UI.WebControls.TextBox)(LoginView1.Controls[0].Controls[1].Controls[0].Controls[1])).Text;
 
        if(Roles.IsUserInRole(txtUsername, "Candidate"))
        {
            this.Response.Redirect("~/Candidate/default.aspx");
        }
        else if(Roles.IsUserInRole(txtUsername, "Employer"))
        {
            this.Response.Redirect("~/Employer/default.aspx");
        }
    }

Open in new window

0
ahllCommented:
No...you have to do that in the "bridge" page.

The login page will automatically redirect everybody to the page you especify in DestinationPageUrl. Is in that page where you redirect the logged user depending on the role.

In my example above it would be menu.aspx
0

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
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
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.