Question

I've set up BetterCMS in my MVC4 app. and it seems like it's working except I can't figure out how to configure it to use Simple Membership Provider that comes with MVC4 internet app.

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

please help!. thanks

EDIT: I've created my MVC4 app using Internet Template which comes with Simple Membership Provider already configured and working. I would like to have those members I've "registered" as BetterCMS users.

Was it helpful?

Solution

If you want to use Better CMS, use BetterCms.Module.Users module from NuGet with it's role provider, membership provider and UI for managing users. How to setup users module, you can read in BetterCMS wiki pages on Github

But if you still wish to use Better CMS with Simple Membership Provider, follow steps below. That's what I've done and it works fine for me.

  1. Create an MVC 4 solution and select Internet template
  2. Run the application and create a user
  3. Install BetterCMS by following steps, explained in Better CMS github wiki, section "Project Setup".
  4. Do not forget to remove default routes registration (routes.MapRoute(name: "Default" ....) from RouteConfig class. Register routes below in the RouteConfig class. After that MVC home page can be reached by URL /home/:

            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. Add role provider and membership provider to web.config (solution found here):

            <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. Add LazyInitializer to global.asax as explained here

  7. Remove [InitializeSimpleMembership] attribute from AccountController, because database connection is already initialized. Also, SMP2.Filters.InitializeSimpleMembershipAttribute class can also be deleted.
  8. Create an admin role and assign it for user (it can be done using ASP.NET Configuration or directly in the database). For example, create role with name "Role1".
  9. There are two ways to set up administrator roles for the user (you can read more in the Better CMS Github Wiki, topic "CMS configuration"):

    • Set your created role as full access role (cms.config, security section's fullAccessRoles attribute set to fullAccessRoles="Role1" )
    • Add roles mappings in the cms.config's security section:

          <customRoles>
              <add permission="BcmsEditContent" roles="Role1" />
              <add permission="BcmsPublishContent" roles="Role1" />
              <add permission="BcmsDeleteContent" roles="Role1" />
              <add permission="BcmsAdministration" roles="Role1" />
          </customRoles>
      
  10. Run application. Go to url /account/login and log-in using admininstrator account, which was created in the 2nd step. Then go back to any CMS page, for example, root page (/). Here you go, you're connected as administrator and CMS sidebar is availabe for web site editing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top