You can add a custom Role Provider class inherited from RoleProvider and override the functions. After adding the class, change your default provider name in the web config
For Example:
Add a class named CustomRoleProvider to you Appcode folder
using System;
using System.Collections.Specialized;
using System.Web.Security;
namespace TestApp.AppCode
{
public class CustomRoleProvider : RoleProvider
{
public override string ApplicationName { get; set; }
public override void Initialize(string name, NameValueCollection config)
{
base.Initialize(name, config);
}
public override bool IsUserInRole(string username, string roleName)
{
string[] roles = GetRolesForUser(username);
foreach (string role in roles)
{
if (role.Equals(roleName, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
return false;
}
public override string[] GetRolesForUser(string username)
{
//Add code to get user roles
}
public override void AddUsersToRoles(string[] usernames, string[] roleNames){
}
public override void CreateRole(string roleName) { }
public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) { return false; }
public override string[] FindUsersInRole(string roleName, string usernameToMatch) { return null; }
public override string[] GetAllRoles() { return null; }
public override string[] GetUsersInRole(string roleName) { return null; }
public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) { }
public override bool RoleExists(string roleName) { return false; }
}
}
}
Change your web config role provider
<roleManager enabled="true" defaultProvider="CustomRoleProvider" >
<providers>
<clear/>
<add name="CustomRoleProvider" type="TestApp.AppCode.CustomRoleProvider"/>
</providers>
</roleManager>