Sunday, November 17, 2013

How to Allow a Virtual User to Browse on Pages with Saving Profile Values

There is an ability in Sitecore named Virtual Users. It could be used for many purposes, for example emulating of site view and work for different users. There is one limitation described in Security API Cookbook:
You must log in a virtual user only after you assign Roles and Profile properties to them. The Roles and Profile properties that are assigned after logging in are lost upon subsequent request.

This limitation make work with profiles changes useless: you could get profile values, but you couldn't change profile values. For example, saving values for virtual user on WFFM form will not work.  But this limitation could be overcame.

If Sitecore API cookbook requires login after assigning roles and profile properties, you could add your own processor to httpRequestEnd pipeline.

<httpRequestEnd>
     <processor type=" YourNamespace.Pipelines.HttpRequestEnd.LoginVirtualUser,  YourAssemblyName"
patch:after="processor[@type='Sitecore.Pipelines.HttpRequest.EndDiagnostics, Sitecore.Kernel']" />
</httpRequestEnd>

namespace YourNamespace.Pipelines.HttpRequestEnd
{
    using Sitecore.ExperienceExplorer.Business.Helpers;
    using Sitecore.Pipelines.HttpRequest;
    using Sitecore.Security.Authentication;

    //this processor is used for applying settings to profiles of virtual users
    public class LoginVirtualUser : HttpRequestProcessor
    {
      public override void Process(HttpRequestArgs args)
      {
         if (Context.User.RuntimeSettings.IsVirtual)
         {
             AuthenticationManager.Login(Context.User);
         }
      }
    }
}

Voila, now assigning roles and changing profile properties works also for Sitecore virtual users.

Monday, February 18, 2013

Extension of Sitecore ECM ContactProfile

In this post is described a way how Email Campaign Manager personalization fields could be extended with calculated fields. By default you can output user profile fields that are present in /sitecore/templates/Modules/EmailCampaign/ Subscriber template. You can use this profile fields in email by using profile names that are surrounded by dollar signs(e.g.: $firstname$, $lastname$). Calculated user profile fields could be useful when you want to output data based on current date.
Sitecore Email Campaign Manager has a lot of abilities to be extended. One of the ways to extend it is change TypeResolver in Sitecore.EmailCampaign.config:
<TypeResolver type="YourNamespace.TypeResolver, YourAssembly" singleInstance="true" />
You are able to override in TypeResolver functions:
ContactList CreateCorrectContactList(string systemName)
Contact GetCorrectAnonymouseFromEmail(string email, ManagerRoot root)
Contact GetCorrectContactFromName(string userName)
ContactList GetCorrectContactListFromName(string contactListName)
ContactProfile GetCorrectContactProfile()
ManagerRoot GetCorrectManagerRootObject(Item rootItem)
LocalSettingsBase GetCorrectLocalSettingsObject(ManagerRoot root)
MessageItem GetCorrectMessageObject(Item item)
PostalEngineBase GetCorrectPostalEngine()
TargetAudience GetCorrectTargetAudience(Item item)

In our case we override GetCorrectContactProfile function:
namespace YourNamespace
{
  /// <summary>
  /// Extended Type Resolver to return extended contact profile
  /// </summary>
  public class TypeResolver : Sitecore.Modules.EmailCampaign.Core.TypeResolver
  {
    /// <summary>
    /// Gets the correct contact profile.
    /// </summary>
    /// <returns></returns>
    public override Sitecore.Modules.EmailCampaign.ContactProfile GetCorrectContactProfile()
    {
      return new ContactProfile();
    }
  }
}

The new ContactProfile is inherited from Sitecore.Modules.EmailCampaign.ContactProfile:
namespace YourNamespace
{
  /// <summary>
  /// Contact profile extended with ability to get calculated user profile properties
  /// </summary>
  public class ContactProfile : Sitecore.Modules.EmailCampaign.ContactProfile
  {
    /// <summary>
    /// Gets a named property value.
    /// </summary>
    /// <param name="propertyName">Name of the property.
    ///             </param>
    /// <returns>
    /// The value.
    /// </returns>
    protected override object GetPropertyValueCore(string propertyName)
    {
      //Here should be your code that will calculate Contact Profile value
    }

    /// <summary>
    /// Gets or sets a profile property value indexed by the property name.
    /// </summary>
    /// <param name="propertyName">The name of the profile property.</param>
    /// <returns>
    /// The value of the specified profile property, typed as object.
    /// </returns>
    public override string this[string propertyName]
    {
      get
      {
        //Here should be your code that will calculate Contact Profile value
      }
      set
      {
        base[propertyName] = value;
      }
    }
  }
}

Now you are able to use your own calculated values for personalization of emails.

Saturday, February 16, 2013

Sitecore Media Library Features & WebClient Error Relation

You will get “Web Client Service is Unavailable” while installation on Windows 2008 server without any configuration. There is a good article that describes possible problems. But if you don’t follow prerequisites described in article you still should be able to install Sitecore. And major part of functionality will work. But WebDav will not work.

webservicenotavailable

WebDAV - Web Distributed Authoring and Versioning. It is an extension of the Hypertext Transfer Protocol. WebDav allows user to work with files saved on web server. It used in Sitecore Media Library for drag and drop ability and other files operations.

Capture111

WebDav requires “Desktop experience” server feature. The Desktop Experience feature allows you to use Windows 7 features on your Windows Server 2008.

Also, don’t forget to add your Sitecore site to trusted sites or allows IE to load to launch programs and files in an iframe. Otherwise you will get empty drag and drop window without ability to edit folder content.

Iframe