2

我已经在我的 MVC4 应用程序中设置了 BetterCMS。似乎它正在工作,只是我不知道如何配置它以使用 MVC4 互联网应用程序附带的简单成员资格提供程序。

http://www.devbridge.com/articles/better-cms-for-developers

请帮忙!。谢谢

编辑:我已经使用 Internet 模板创建了我的 MVC4 应用程序,该模板附带了简单的会员资格提供程序已经配置和工作。我想让那些我“注册”为 BetterCMS 用户的成员。

4

1 回答 1

6

如果您想使用 Better CMS,请使用来自 NuGet 的 BetterCms.Module.Users 模块及其角色提供程序、成员资格提供程序和用于管理用户的 UI。如何设置用户模块,您可以在 Github 上的 BetterCMS wiki 页面中阅读

但是,如果您仍然希望通过 Simple Membership Provider 使用 Better CMS,请按照以下步骤操作。这就是我所做的,对我来说效果很好。

  1. 创建 MVC 4 解决方案并选择 Internet 模板
  2. 运行应用程序并创建用户
  3. 通过以下步骤安装 BetterCMS,在Better CMS github wiki,“项目设置”部分中进行了说明。
  4. 不要忘记routes.MapRoute(name: "Default" ....从 RouteConfig 类中删除默认路由注册 ( )。在 RouteConfig 类中注册以下路由。之后,可以通过 URL /home/ 访问 MVC 主页:

            routes.MapRoute("mvc-account-controller", "account/{action}/{id}", new
                {
                    area = string.Empty,
                    controller = "Account",
                    action = "Login",
                    id = UrlParameter.Optional
                });
    
            routes.MapRoute("mvc-home-controller", "home/{action}/{id}", new
                {
                    area = string.Empty,
                    controller = "Home",
                    action = "Index",
                    id = UrlParameter.Optional
                });
    
  5. 将角色提供者和成员资格提供者添加到 web.config(在此处找到解决方案):

            <roleManager enabled="true" defaultProvider="simple">
                <providers>
                    <clear/>
                    <add name="simple" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData"/>
                </providers>
            </roleManager>
            <membership defaultProvider="simple">
                <providers>
                    <clear/>
                    <add name="simple" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"/>
                </providers>
            </membership>
    
  6. 如此处所述,将 LazyInitializer 添加到 global.asax

  7. 从 AccountController 中移除 [InitializeSimpleMembership] 属性,因为数据库连接已经初始化。此外,还可以删除 SMP2.Filters.InitializeSimpleMembershipAttribute 类。
  8. 创建管理员角色并将其分配给用户(可以使用 ASP.NET 配置或直接在数据库中完成)。例如,创建名称为“Role1”的角色。
  9. 有两种方法可以为用户设置管理员角色(您可以在Better CMS Github Wiki 中阅读更多内容,主题“CMS 配置”):

    • 将您创建的角色设置为完全访问角色(cms.config,安全部分的 fullAccessRoles 属性设置为fullAccessRoles="Role1"
    • 在 cms.config 的安全部分添加角色映射:

          <customRoles>
              <add permission="BcmsEditContent" roles="Role1" />
              <add permission="BcmsPublishContent" roles="Role1" />
              <add permission="BcmsDeleteContent" roles="Role1" />
              <add permission="BcmsAdministration" roles="Role1" />
          </customRoles>
      
  10. 运行应用程序。转到 url /account/login 并使用在第二步中创建的管理员帐户登录。然后返回到任何 CMS 页面,例如根页面 (/)。在这里,您已以管理员身份连接,并且 CMS 侧边栏可用于网站编辑。

于 2013-11-06T06:12:43.560 回答