Scott Clarke
Scott Clarke

Reputation: 33

SQL Database Powered C# & ASP.Net Role based authentication control

I want an ASP.net and C# authentication/logon control which references a SQL server database containing two tables: users and roles. When the authentication is successful, I want the user to be redirected to a specific page on the website determined by their role stored in the database.

For example, a user with a role of "System Admin" would be directed to the protected home page within the system admin folder on the site where as a role of "System User" would be redirected to their respective home page within the protected system user folder.

I managed to find something on the MSDN library but this redirects all successful logons to "default.aspx" regardless.

Is there a way to:

  1. A way to alter this to my specific requirements?
  2. A resource that I havent found yet that could provide some pointers into how to implement this?

Upvotes: 3

Views: 1168

Answers (2)

Loktar
Loktar

Reputation: 35309

You could always have a proxy login successful page, that gets the role after a successful login and redirects to the subsequent page.

code behind of the successful default.aspx login.

if(Context.User.IsInRole("System Admin")){
    //redirect to page.
}

Upvotes: 0

Wyatt Barnett
Wyatt Barnett

Reputation: 15673

You can easily get there with the built-in SqlMembershipProvider and SqlRoleProvider present in ASP.NET since version 2.0.

Real problem is determing what "role" a user should be in when they have multiples.

Upvotes: 1

Related Questions