本文整理汇总了C#中RoleManager类的典型用法代码示例。如果您正苦于以下问题:C# RoleManager类的具体用法?C# RoleManager怎么用?C# RoleManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RoleManager类属于命名空间,在下文中一共展示了RoleManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: UserController
public UserController(IUserService service, RoleManager<IdentityRole> roleManager, IClanService clanService)
{
Service = service;
RoleManager = roleManager;
UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
ClanService = clanService;
}
开发者ID:hstjep,项目名称:EvidencijaClanovaWebAPI,代码行数:7,代码来源:UserController.cs
示例2: AccountController
public AccountController(
UserManager userManager,
IMultiTenancyConfig multiTenancyConfig,
IUserEmailer userEmailer,
RoleManager roleManager,
TenantManager tenantManager,
IUnitOfWorkManager unitOfWorkManager,
ITenancyNameFinder tenancyNameFinder,
ICacheManager cacheManager,
IAppNotifier appNotifier,
IWebUrlService webUrlService,
AbpLoginResultTypeHelper abpLoginResultTypeHelper,
IUserLinkManager userLinkManager,
INotificationSubscriptionManager notificationSubscriptionManager)
{
_userManager = userManager;
_multiTenancyConfig = multiTenancyConfig;
_userEmailer = userEmailer;
_roleManager = roleManager;
_tenantManager = tenantManager;
_unitOfWorkManager = unitOfWorkManager;
_tenancyNameFinder = tenancyNameFinder;
_cacheManager = cacheManager;
_webUrlService = webUrlService;
_appNotifier = appNotifier;
_abpLoginResultTypeHelper = abpLoginResultTypeHelper;
_userLinkManager = userLinkManager;
_notificationSubscriptionManager = notificationSubscriptionManager;
}
开发者ID:Zbun,项目名称:Gld.Activity.Project,代码行数:29,代码来源:AccountController.cs
示例3: DevelopmentDefaultData
public DevelopmentDefaultData(IOptions<DevelopmentSettings> options, IDataContext dataContext, UserManager<User> userManager, RoleManager<Role> roleManager)
{
this.settings = options.Value;
this.dataContext = dataContext;
this.userManager = userManager;
this.roleManager = roleManager;
}
开发者ID:Supermakaka,项目名称:mvc6,代码行数:7,代码来源:DevelopmentDefaultData.cs
示例4: AddUserAndRole
internal void AddUserAndRole()
{
// access the application context and create result variables.
Models.ApplicationDbContext context = new ApplicationDbContext();
IdentityResult IdRoleResult;
IdentityResult IdUserResult;
// create roleStore object that can only contain IdentityRole objects by using the ApplicationDbContext object.
var roleStore = new RoleStore<IdentityRole>(context);
var roleMgr = new RoleManager<IdentityRole>(roleStore);
// create admin role if it doesn't already exist
if (!roleMgr.RoleExists("admin"))
{
IdRoleResult = roleMgr.Create(new IdentityRole { Name = "admin" });
}
// create a UserManager object based on the UserStore object and the ApplicationDbContext object.
// defines admin email account
var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
var appUser = new ApplicationUser
{
UserName = "[email protected]",
Email = "[email protected]"
};
IdUserResult = userMgr.Create(appUser, "Pa$$word1");
// If the new admin user was successfully created, add the new user to the "admin" role.
if (!userMgr.IsInRole(userMgr.FindByEmail("[email protected]").Id, "admin"))
{
IdUserResult = userMgr.AddToRole(userMgr.FindByEmail("[email protected]").Id, "admin");
}
}
开发者ID:SCCapstone,项目名称:ZVerse,代码行数:33,代码来源:RoleActions.cs
示例5: Initialize
public static void Initialize(MacheteContext DB)
{
IdentityResult ir;
var rm = new RoleManager<IdentityRole>
(new RoleStore<IdentityRole>(DB));
ir = rm.Create(new IdentityRole("Administrator"));
ir = rm.Create(new IdentityRole("Manager"));
ir = rm.Create(new IdentityRole("Check-in"));
ir = rm.Create(new IdentityRole("PhoneDesk"));
ir = rm.Create(new IdentityRole("Teacher"));
ir = rm.Create(new IdentityRole("User"));
ir = rm.Create(new IdentityRole("Hirer")); // This role is used exclusively for the online hiring interface
var um = new UserManager<ApplicationUser>(
new UserStore<ApplicationUser>(DB));
var user = new ApplicationUser()
{
UserName = "jadmin",
IsApproved = true,
Email = "[email protected]"
};
ir = um.Create(user, "ChangeMe");
ir = um.AddToRole(user.Id, "Administrator"); //Default Administrator, edit to change
ir = um.AddToRole(user.Id, "Teacher"); //Required to make tests work
DB.Commit();
}
开发者ID:SavageLearning,项目名称:Machete,代码行数:28,代码来源:MacheteUsers.cs
示例6: ChangeRoleOfUserInGroup
public ActionResult ChangeRoleOfUserInGroup(string mail)
{
//SKapa VM instans
UserChangeRoleViewModel changeVM = new UserChangeRoleViewModel();
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
//Välj en user till Viewmodell
//ViewBag.Name = changeVM.Name;
changeVM.Users = repo.ApplicationUsers().Select(u => new SelectListItem
{
Text = u.UserName,
Value = u.Id,
});
//ApplicationUser usr = repo.ApplicationUsers().First();
//Välj vilken av users roll som skall ändras
//List<IdentityRole> cVM = new List<IdentityRole>();
changeVM.SelectedUser = repo.ApplicationUsers().Single(m => m.Email == mail).Id;
changeVM.OldRoles = userManager.GetRoles(changeVM.SelectedUser).Select(o => new SelectListItem
{
Text = o,
Value = o
});
//Välj en ny roll till Viewmodell
changeVM.Roles = repo.RolesList().Select(r => new SelectListItem
{
Text = r.Name,
Value = r.Name
});
//Returna View med VM
return View(changeVM);
}
开发者ID:jarolex,项目名称:Personalsystem-1,代码行数:31,代码来源:GroupController.cs
示例7: Users
public ActionResult Users()
{
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(db));
if (!roleManager.RoleExists("user"))
{
var nRole = new IdentityRole("user");
roleManager.Create(nRole);
}
if (!roleManager.RoleExists("admin"))
{
var nRole = new IdentityRole("admin");
roleManager.Create(nRole);
}
if (!roleManager.RoleExists("moderator"))
{
var nRole = new IdentityRole("moderator");
roleManager.Create(nRole);
}
if (!roleManager.RoleExists("journalist"))
{
var nRole = new IdentityRole("journalist");
roleManager.Create(nRole);
}
var vm = new AdminUsersViewModel();
vm.Users = db.Users.OrderBy(x => x.UserName).ToList();
vm.Roles = db.Roles.ToList();
return View(vm);
}
开发者ID:mjdean1994,项目名称:Athenaeum,代码行数:31,代码来源:AdminController.cs
示例8: UserRepository
public UserRepository()
{
UserManager =
new UserManager<ApplicationUser>(
new UserStore<ApplicationUser>(ApplicationDbContext.Create()));
RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(ApplicationDbContext.Create()));
}
开发者ID:LekoWebDeveloper,项目名称:webapi-template,代码行数:7,代码来源:UserRepository.cs
示例9: UserService
public UserService(DbContext context, IRepository<User> users, IRepository<Message, int> messages)
{
this.users = users;
this.messages = messages;
this.userManager = new UserManager<User>(new UserStore<User>(context));
this.roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
}
开发者ID:atanas-georgiev,项目名称:ASP.NET-MVC-Final-Project,代码行数:7,代码来源:UserService.cs
示例10: SeedRolesAndUsers
private void SeedRolesAndUsers(ETCCanadaContext context)
{
RoleManager<ApplicationRole> roleManager = new RoleManager<ApplicationRole>(new RoleStore<ApplicationRole>(context));
if (!roleManager.RoleExists("Administrator"))
{
roleManager.Create(new ApplicationRole("Administrator"));
}
if (!roleManager.RoleExists("User"))
{
roleManager.Create(new ApplicationRole("User"));
}
List<ApplicationUser> users = new List<ApplicationUser>();
ApplicationUser user1 = new ApplicationUser { UserName = "[email protected]", Email = "[email protected]", FirstName = "Administrator", LastName = "Administrator", IsApproved = true };
ApplicationUser user2 = new ApplicationUser { UserName = "[email protected]", Email = "[email protected]", FirstName = "User", LastName = "User", IsApproved = true };
users.Add(user1);
users.Add(user2);
SeedDefaultUser(context, user1, "Administrator");
SeedDefaultUser(context, user2, "User");
//http://stackoverflow.com/questions/20470623/asp-net-mvc-asp-net-identity-seeding-roles-and-users
//http://stackoverflow.com/questions/19280527/mvc5-seed-users-and-roles
//http://stackoverflow.com/questions/19745286/asp-net-identity-db-seed
}
开发者ID:majurans,项目名称:ETCCanada,代码行数:27,代码来源:DataSeeder.cs
示例11: Create
public async Task<ActionResult> Create(UserRoles role)
{
if (ModelState.IsValid)
{
// Create a RoleStore object by using the ApplicationDbContext object.
// The RoleStore is only allowed to contain IdentityRole objects.
var roleStore = new RoleStore<IdentityRole>(context);
// Create a RoleManager object that is only allowed to contain IdentityRole objects.
// When creating the RoleManager object, you pass in (as a parameter) a new RoleStore object.
var roleMgr = new RoleManager<IdentityRole>(roleStore);
// Then, you create the "Administrator" role if it doesn't already exist.
if (!roleMgr.RoleExists(role.RoleName))
{
IdRoleResult = roleMgr.Create(new IdentityRole(role.RoleName));
if (IdRoleResult.Succeeded)
{ // Handle the error condition if there's a problem creating the RoleManager object.
ViewBag.StatusMessage = "Role has been added Successfully";
}
else
{
ViewBag.StatusMessage = "The Role Already Exists";
}
}
}
// If we got this far, something failed, redisplay form
return View();
}
开发者ID:Jaanzaib,项目名称:PilotProject,代码行数:28,代码来源:RolesController.cs
示例12: AdminController
public AdminController(
IAuthorizationService authorizationService,
ITypeFeatureProvider typeFeatureProvider,
ISession session,
IStringLocalizer<AdminController> stringLocalizer,
IHtmlLocalizer<AdminController> htmlLocalizer,
ISiteService siteService,
IShapeFactory shapeFactory,
RoleManager<Role> roleManager,
IRoleProvider roleProvider,
INotifier notifier,
IEnumerable<IPermissionProvider> permissionProviders
)
{
TH = htmlLocalizer;
_notifier = notifier;
_roleProvider = roleProvider;
_typeFeatureProvider = typeFeatureProvider;
_permissionProviders = permissionProviders;
_roleManager = roleManager;
_shapeFactory = shapeFactory;
_siteService = siteService;
T = stringLocalizer;
_authorizationService = authorizationService;
_session = session;
}
开发者ID:jchenga,项目名称:Orchard2,代码行数:26,代码来源:AdminController.cs
示例13: AuthRepository
public AuthRepository()
{
_ctx = new NotificacionesContext();
var store = new UserStore<ApplicationUser>(_ctx);
_userManager = new UserManager<ApplicationUser>(store);
_roleManaller = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(_ctx));
}
开发者ID:manuelbautista,项目名称:NotificationSystem,代码行数:7,代码来源:AuthRepository.cs
示例14: Configuration
public void Configuration(IAppBuilder app)
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
RouteConfig.RegisterRoutes(RouteTable.Routes);
MappingConfig.RegisterMapping();
ConfigureOAuth(app);
app.UseCors(CorsOptions.AllowAll);
UserManagerFactory = () =>
{
var usermanager =
new UserManager<IdentityEmployee>(new UserStore<IdentityEmployee>(new IdentityContext()));
usermanager.UserValidator = new UserValidator<IdentityEmployee>(usermanager)
{
AllowOnlyAlphanumericUserNames = false
};
return usermanager;
};
RoleManagerFactory = () =>
{
var rolemanager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new IdentityContext()));
return rolemanager;
};
}
开发者ID:DominicCooke,项目名称:HolidayBooking,代码行数:28,代码来源:Startup.cs
示例15: Application_Start
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
// Tạo role sẵn
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
List<string> roleNameList = new List<string> { "Admin"
, "Designer"
, "Mod"
, "Uploader"
, "Subteam"
, "Subber"
, "VIP"
, "Member" };
foreach (string roleName in roleNameList)
{
if (!roleManager.RoleExists(roleName))
{
var newRole = new IdentityRole();
newRole.Name = roleName;
roleManager.Create(newRole);
}
}
}
开发者ID:taihdse60630,项目名称:a4s,代码行数:28,代码来源:Global.asax.cs
示例16: UserController
public UserController(IEmployeeDataService employeeDataService, ITeamDataService teamDataService)
{
this.employeeDataService = employeeDataService;
this.teamDataService = teamDataService;
roleManager = Startup.RoleManagerFactory();
userManager = Startup.UserManagerFactory();
}
开发者ID:DominicCooke,项目名称:HolidayBooking,代码行数:7,代码来源:UserController.cs
示例17: GetUsersCountInRole
public int GetUsersCountInRole(string role)
{
var roleStore = new RoleStore<IdentityRole>(this.dbContext);
var roleManager = new RoleManager<IdentityRole>(roleStore);
int count = roleManager.FindByName(role).Users.Count;
return count;
}
开发者ID:simeonpp,项目名称:Trip-Destination,代码行数:7,代码来源:UserServices.cs
示例18: CreateRole
public bool CreateRole(string name)
{
var rm = new RoleManager<IdentityRole>(
new RoleStore<IdentityRole>(new ApplicationContext()));
IdentityResult idResult = rm.Create(new IdentityRole(name));
return idResult.Succeeded;
}
开发者ID:khoaht,项目名称:AngularJSDemo,代码行数:7,代码来源:AccountService.cs
示例19: Insert
public JsonData Insert(IdentityRole entity, string userId)
{
try
{
using (var db = new DataContext())
{
if (entity == null) throw new ArgumentNullException("The new" + " record is null");
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(db));
//Create Roles if they do not exist
if (!roleManager.RoleExists(entity.Name))
{
roleManager.Create(new IdentityRole(entity.Name));
}
db.SaveChanges();
return DataHelpers.ReturnJsonData(entity, true, "Saved successfully", 1);
}
}
catch (Exception e)
{
return DataHelpers.ExceptionProcessor(e);
}
}
开发者ID:biggash730,项目名称:SemanticUI_Knockout_ASPMVC_Starter,代码行数:25,代码来源:RoleRepo.cs
示例20: UserController
public UserController(IUserService service, IRedService redService, RoleManager<IdentityRole> roleManager)
{
Service = service;
RedService = redService;
RoleManager = roleManager;
UserManager = new UserManager<ApplicationUserEntity>(new UserStore<ApplicationUserEntity>(new SearchContext()));
}
开发者ID:Nodios,项目名称:RepacMono,代码行数:7,代码来源:UserController.cs
注:本文中的RoleManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论