SQL Database Powered C # and ASP.Net Role-Based Authentication Management

I want ASP.NET and C # authentication / login control, which refers to 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 defined by their role stored in the database.

For example, a user with the role "System Administrator" will be redirected to the secure home page in the system administrator’s folder on the site, where as the role "System User" will be redirected to the corresponding home page within the user folder of the protected system.

I managed to find something in the MSDN library, but it independently redirects all successful logins to "default.aspx".

Is there any way:

  • A way to change this to my specific requirements?
  • A resource that I have not yet found that can provide some pointers on how to implement this?
+3
source share
2 answers

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

The real problem is determining what role the user should have when they have multiplicity.

+1
source

-, .

default.aspx.

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

Source: https://habr.com/ru/post/1790489/


All Articles