Thursday, April 2, 2009

Role Based Security Implementation in AspNet

http://www.asp.net/security/tutorials/role-based-authorization-cs
http://www.codeguru.com/csharp/.net/net_security/authentication/article.php/c7415 [zip file at the end of the file.]

Setting in web.config
=====================
< connectionStrings>
< add name="myDbConnection" connectionString ="Server=43.455.565.67;database=mydatabasename;uid=arindam;pwd=passmenow;" />
< /connectionStrings>

< roleManager enabled="true" defaultProvider="SqlRoleManager" >
< providers>
< add name="SqlRoleManager" type="System.Web.Security.SqlRoleProvider" connectionStringName="myDbConnection" applicationName="MyApplication" />
< /providers>
< /roleManager>


Create the following set of tables to support the role based authorization and security system.

Ceate table User
(
UserID - pk
Username varchar(20),
Password varchar(20)
)

Ceate table SecurityGroupAssigns
(
AssignID - pk
UserID - fk
SecurityGroupId - fk
)


Ceate table SecurityGroup
(
SecurityGroupId - pk
Name
DisplayName
)


Create Table SecurityRightAssign
(
AssignID - PK
SecurityGroupId - fk
SecurityRightID - fk
)

Create Table SecurityRight
(
SecurityRightID - PK
SecurityRight - varchar
)