How to redirect to specific page based on specific role in ASP.net 3.5?

Hello,

I'm currently working on a login page and pretty much have a basics down. I'm using the web administration tool and have two roles (admin & regular). I've created two folders wihtin the project, admin and regular. All I need to do now is when the user logs in as an admin, they will go to the admin_page.aspx, and for the regular user, they will go to monitor.aspx. I thought utitlizing a custom handler would help me, but I just realized that it's going to further secure my admin folder instead of redirecting me. Is there a way I can implement this? Thank you so much for your help.
weihkAsked:
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.

ppittleCommented:
Give this a shot:

<%-- Mark Up--%>
<asp:login id="Login1" runat="server" onloggedin="Login1_LoggedIn">

<%-- Code Behind --%>
 protected void Login1_LoggedIn(object sender, EventArgs e)
    {
        if (HttpContext.Current.User.IsInRole("Admin"))
        {
            Response.Redirect("Admin_Page.aspx");
        }
        else
        {
            Response.Redirect("monitor.aspx");
        }
    }
0
weihkAuthor Commented:
i forgot to mention...this is in vb

should i use protected sub or something else?
0
ppittleCommented:
In Visual Studio, open your aspx page in designer.  Make sure the Property window is visible, (View-> Properties Window).  Select you Login control.  In the properties click the Events button (looks like orange lightining bult) and then double click LoggedIn.  This will have Visual Studio automatically create the event handler for you.

Otherwise, my VB is rather rusty.  I think it should look like:
Protected Sub Login1_LoggedIn(ByVal sender As System.Object,  ByVal e As System.EventArgs) _
   Handles Login1.LoggedIn
if (HttpContext.Current.User.IsInRole("Admin"))
      then
            Response.Redirect("Admin_Page.aspx");
       
        else
       
            Response.Redirect("monitor.aspx");
        end if

End Sub

0
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

weihkAuthor Commented:
there was an error...it works going to monitor.aspx but for some reason it's not reading the admin role to go to admin page.

so what i did was i deleted monitor.aspx leaving it empty and left admin page alone and it gave me this error:

Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
0
weihkAuthor Commented:
when i look at the code, it says the same thing under Login1 (error line).LoggedIn

Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
0
ppittleCommented:
That sounds like it has something to with the Handle you wrote.  Try the code without the HttpHandle inlcuded in your WebSite
0
weihkAuthor Commented:
i tried getting rid of the httphandle and it still gives me those errors. could it be something else?
0
ppittleCommented:
Can you post your full markup and codebehind.
0
weihkAuthor Commented:
i fixed the problem with the httphandle so i'm not getting that error. however, what i'm getting now is if I don't have anything under the Else response.redirect("") and have the if part redirect to some other page it will redirect the page to the default.aspx. so I'm wonderinf if the httpcontext.current.user.IsInRole("admin") is working or not? what are your thoughts?
0
weihkAuthor Commented:
sorry if i'm not clear, but overall what im trying to say is, if everything passes (username and password), the login page will redirect to the default.aspx and not the admin_page.aspx which is what we want.

but, if i have something under the else statement, it will redirect to the monitor.aspx, which i'm finding quite odd. If the arguement is passing through and not reaching the role segment and immediately passing through the else statement (redirecting to the monitor.aspx) then is it a logic or a syntax error? thanks for your help.
0
ppittleCommented:
can you post the markup and the code behind for your login page?
0
weihkAuthor Commented:
good news! i searched extensively throughout the night for solutions and was able to find one:

If Roles.IsUserInRole(Login1.UserName, "admin") = False Then
            Response.Redirect("monitor.aspx")
        Else
            Response.Redirect("admin/admin_page.aspx")
        End If

this one worked, and i do not have any complaints with this. thanks for your help. i really appreciate it.
0
weihkAuthor Commented:
i want to reward you the points but if i accept my solution that i have will you get the points?
0
ppittleCommented:
Glad to hear you found a solution that worked for you!  

I believe you can mark your solution and one of my posts as partial solutions, which will allow you to allocate points appropriatly.  Alternatively, you can mark one of my posts as the "solution".  When you hit this button, you'll be given the opportunity to add a comment, which will then appear within the post marked as "solution"  You can a comment along the lines of

"ppittle's solution pointed me in the correct direction, however this was the final solution:
If Roles.IsUserInRole(Login1.UserName, "admin") = False Then
            Response.Redirect("monitor.aspx")
        Else
            Response.Redirect("admin/admin_page.aspx")
        End If"

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
weihkAuthor Commented:
it's ok, i'll just mark the previous comment as the solution, thanks once again for your help.
0
weihkAuthor Commented:
ppittle help has lead to the solution
0
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.