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


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to Redirect the User to a new page , based on their role in ASP .NET

Posted By:Fahim       Posted Date: September 24, 2010    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

This article describes how to automatically redirect users upon login, based upon their role membership.
 

I am going to explain how to Redirect the User to a new page after Successful logging in, based on their role membership in C# ASP .NET web application.

Redirecting users, upon login, based on their role can be as simple as adding a few if/else statements and a Response.Redirect call in the LoggedIn Event of Login Control.



protected void Login1_LoggedIn(object sender, EventArgs e)
{
        if (Roles.IsUserInRole(Login1.UserName, "Admin"))
        {

            Response.Redirect("~/Adminstrator/GeneratorStatus.aspx");
            
        }

        else if (Roles.IsUserInRole(Login1.UserName, "Registered Users"))
        {

            Response.Redirect("~/RegisteredUsers/Dashboard.aspx");
           
        }
        else if (Roles.IsUserInRole(Login1.UserName, "Developers"))
        {

            Response.Redirect("~/Home.aspx");
        }
}



Thank You

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply

    Read also another Resources from the same Author

  • LINQ to SQL
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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