Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- If user.IsInRole("Admin") Then
- deleteButton.Visible = True
- else
- deleteButton.Visible = False
- public interface ICustomRole
- {
- bool IsInRole(string userName, object[] params roles);
- }
- public class MyCustomRole : RoleProvider, ICustomRole
- {
- public IsInRole(MembershipUser user, object[] params roles)
- {
- if (roles == null || roles.Length == 0)
- throw new ArgumentException("roles");
- // Put your logic here for accessing the roles
- }
- }
- bool isValid = ((ICustomRole)Roles.Provider).IsInRole(
- User, new[] { "Admin", "Moderator", "Validator" });
- if user.isInRole("Admin") then
- deleteButton.visible = true
- else
- deleteButton.visible = false
- if user.isInRole("Admin","Moderator") then
- deleteButton.visible = true
- else
- deleteButton.visible = false
- User(UserID, ...) PK = UserID
- Role(RoleID, RoleName, ...) PK = RoleID
- UserHasRole(UserHasRoleID, UserID, RoleID) PK=UserHasRoleID ; Unique= (UserID, RoleID)
- public class YourSqlRoleProvider : System.Web.Security.RoleProvider
- {
- private string ConnectionString { get; set; }
- public override void AddUsersToRoles(string[] userNames, string[] roleNames)
- {
- // logic here
- }
- public override string ApplicationName
- {
- get
- {
- throw new NotSupportedException();
- }
- set
- {
- throw new NotSupportedException();
- }
- }
- public override void CreateRole(string roleName)
- {
- throw new NotSupportedException();
- }
- public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
- {
- throw new NotSupportedException();
- }
- public override string[] FindUsersInRole(string roleName, string userNameToMatch)
- {
- throw new NotSupportedException();
- }
- public override string[] GetAllRoles()
- {
- // logic here
- }
- public override string[] GetRolesForUser(string userName)
- {
- // logic here
- }
- public override string[] GetUsersInRole(string roleName)
- {
- throw new NotSupportedException();
- }
- public override bool IsUserInRole(string userName, string roleName)
- {
- return GetRolesForUser(userName).Contains(roleName);
- }
- public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
- {
- this.ConnectionString = ConfigurationManager.ConnectionStrings[config["connectionStringName"]].ConnectionString;
- base.Initialize(name, config);
- }
- public override void RemoveUsersFromRoles(string[] userNames, string[] roleNames)
- {
- throw new NotSupportedException();
- }
- public override bool RoleExists(string roleName)
- {
- throw new NotSupportedException();
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <configuration>
- <connectionStrings>
- <clear />
- <add name="YourConnectionString" providerName="System.Data.SqlClient" connectionString="connection string here" />
- </connectionStrings>
- <system.web>
- <roleManager defaultProvider="YourSqlRoleProvider" enabled="true">
- <providers>
- <clear />
- <add name="YourSqlRoleProvider" type="YourSqlRoleProvider" connectionStringName="YourConnectionString" />
- </providers>
- </roleManager>
- </system.web>
- </configuration>
Add Comment
Please, Sign In to add comment