使用專案範本實作 ASP.NET MVC Sitemap 及 Roles

Step01.新增一個含有identity的專案範本
Step02.將專案的identity角色功能打開

在App_Start的IdentityConfig.cs 加入

//增加角色管理員相關的設定
public class ApplicationRoleManager : RoleManager<IdentityRole>
{
    public ApplicationRoleManager(IRoleStore<IdentityRole, string> roleStore): base(roleStore)
    {
    }

    public static ApplicationRoleManager Create(IdentityFactoryOptions<ApplicationRoleManager> options, IOwinContext context)
    {
        return new ApplicationRoleManager(new RoleStore<IdentityRole>(context.Get<ApplicationDbContext>()));
    }
 }

在App_Start的 Startup.Auth.c s的 public void ConfigureAuth(IAppBuilder app) 加入

//增加角色的OwinContext
app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);

以上這兩個步驟,專案的identity 就具備Role的功能了

Step03.Install-Package MvcSiteMapProvider.MVC5 -Version 4.6.22

閱讀全文〈使用專案範本實作 ASP.NET MVC Sitemap 及 Roles〉