Umbraco, Brock Allen Membership and Content Integration

Since we were working on a multi-tentant solution with Umbraco, we needed a solution as Umbraco's membership did not support multi-tenant out of the box. Discussed in a previous article(Umbraco Multi-Tenant Membership), we chose Brock Allen's Membership Reboot. For the integration with Umbraco multi-tenant, there were three primary tasks: dependency injection update, tenant configuration, and content integration. Here we discuss the issues associated with Content Integration.

When discussing content integration with regards to Membership Reboot and Umbraco, we are referring to being able to control content delivered to end users through the Umbraco admin environment. Here, there are three areas of focus:

  1. Umbraco Views
  2. Response Messages
  3. Emails

 

Membership Reboot and Umbraco Views

The Membership Reboot comes with a set of Controllers and associated Razor views for providing such things as a Login Form, Registration, etc. For a single tenant site with no need to control form content, a developer would likely just need to change the layout of the form to the master layout of the site to get the correct view; possilby some CSS modifications. We wanted to be able to control content on the page through Umbraco. We also wanted to be able to provide different content based upon language. Therefore, we created a one-to-one-to-one correlation of Umbraco document types to Umbraco templates to Reboot Main Views. We also modified the Views to use ajax calls versus page posts.

At its most basic, it is a simple Umbraco View that contains a RenderAction to the Reboot form. Thus, we can manage content through Umbraco that we might otherwise need to make code changes to modify:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage

@{Layout = "AccountMasterLayout.cshtml";}

<div class="container">

@{ Html.RenderAction("Index", "Login", new { area = "MemberAccount" }); }

</div>

The Membership Reboot views contained content in English. In order to support multilingual, we modified snippets such as this

<p>
You are already logged in, but you
tried to access a resource that you do not have permission
for. Please login with an account that does have access
or contact your administrator to grant you access.
</p>

to this:

<p>
@Html.GetTranslatedDicitonaryItem("LoggedInWithoutAccess", "You are already logged in, but tried to access a resource that you do not have permission for. Please login with an account that does have access or contact your administrator to grant you access.")
</p>

The GetTranslatedDictionaryItem creates the Umbraco dictionary item if it does not already exist and allows the message to be controlled through the Umbraco Dictionary.

 

Membership Reboot and Response Messages

The Membership Reboot response messages are defined in Resource Files. An example for retrieving a validation message follows:

public virtual string GetValidationMessage(string id)
{
var cmd = new GetValidationMessage { ID = id };
ExecuteCommand(cmd);
if (cmd.Message != null) return cmd.Message;
var result = Resources.ValidationMessages.ResourceManager.GetString(id, Resources.ValidationMessages.Culture);
if (result == null) throw new Exception("Missing validation message for ID : " + id);
return result;
}

Here following the same pattern above using the GetTranslatedDictionaryItem method, we moved these into the Umbraco dictionary.

 

Membership Reboot Emails

 The Reboot Emails are stored in a text files contained within the solution as embedded resources. The code to retrieve these follows:

const string ResourcePathTemplate = "BrockAllen.MembershipReboot.Notification.Email.EmailTemplates.{0}.txt";
string LoadTemplate(string name)
{
     name = String.Format(ResourcePathTemplate, name);
var asm = typeof(EmailMessageFormatter<>).Assembly;
     using (var s = asm.GetManifestResourceStream(name))
     {
          if (s == null) return null;
          using (var sr = new StreamReader(s))
          {
              return sr.ReadToEnd();
          }
     }
}

Rather than retrieve the emails from the text files, we added an email template that contains fields for subject and body. We added these under our Site Settings node allowing us to control email message by Site and Language.

 

Conclusion

So here we modified the source of the content for both Views, Response Messages and Emails allowing us to control this content through the Umbraco interface. This was rather straightforward once we understood where we needed to make changes.

Overall, Membership Reboot worked for us in regards to integrating a modern claims based authentication service with a multi tenant Umbraco application. For a single tenant, non-content managed application; we think integration should be quite fast. For multi-tenant, however, we would suggest being conservative with estimates for integration. This was approximately a 3 week project for us.

 



About The Author

Avatar
Jonathan Folland

Jonathan Folland is technologist with over 20 years experience in a variety of capacities. He held the position of Vice President of Operations of one of the fastest growing companies in the world. He has led high volume e-Commerce operations and is an expert at mixing technology and finance to produce high return results.


Related Articles