Redirect to page according to role while login using ASP.Net

 

Introduction

In this article i will describe how to redirect to a particular page according to role assigned to the user while login using C# and Asp.Net.

History

In the Previous articles i explained which namespace is used for membership classhow to insert record into access database using vb.nethow to update record into access database using vb.nethow to delete record from access database using vb.net, how to add namespace in vb.net and many more about ASP.Net.

Simply write the below code on LoggedIn event of Login Control

 if (string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
        {
            if (Roles.IsUserInRole(Login1.UserName, "admin"))
            {
                Response.Redirect("~/Account/admin/admin-DashBoard.aspx");
            }
            else if (Roles.IsUserInRole(Login1.UserName, "customer"))
            {
                 Response.Redirect("~/Account/customer/customer-DashBoard.aspx");
            }
        }

Explanation.

As the Above Code is self explainatory. 

Here if user is in role "admin" user will be redirected to "admin-dashboard.aspx" page. And if user is in role customer user will be redirected to "customer-dashboard.aspx" page.

Give your Valuable Comments.
comments powered by Disqus
 
Follow me on twitter
About Me
Harpreet Singh
I began programming with C++ when i was 17. Then at the middle of my study .NET came. Then I began to read C# and VB.NET. By the time i learnt SQL and ASP.NET, and developed some websites such as news portals that are active now. Currently i am running my own Software company.
More Articles