I’m using asp.net 2.0 portal on Sitecore front end in the current project, and personalization features such as portlet drag-n-drop just won’t work unless asp.net understands that the user is logged in and can tell the difference between users.
Here’s my hack-n-slash solution: it envolves shim classes implementing IPrincipal and IIdentity, delegating everything to Sitecore. User id is returned as user name to asp.net, so that each user gets own personalization data (actually user names would also work, since they're unique). On each request, a custom processor in HttpBeginRequest pipeline (named AspnetUserSetter) puts the Sitecore principal in asp.net context.
And since I'm humble enough to allow asp.net do the rest, using default personalization database and provider - it just works. Now I wish it was easier to create custom frames around web parts.
public class SitecorePrincipal : IPrincipal
{
private IIdentity identity;
public IIdentity Identity
{
get { return identity; }
}
public SitecorePrincipal()
{
identity = new SitecoreIdentity();
}
/// <summary>
/// Checks whether Sitecore user is in the given role. Supports both role names and ids.
/// </summary>
public bool IsInRole(string role)
{
if (MainUtil.IsID(role))
return Sitecore.Context.User.IsInRole(ID.Parse(role));
RoleItem roleItem = Sitecore.Context.Domain.GetRole(role);
if (roleItem != null)
return Sitecore.Context.User.IsInRole(roleItem.ID);
else
return false;
}
}
public class SitecoreIdentity : IIdentity
{
public string Name
{
get { return Sitecore.Context.User.ID.ToString(); }
}
public string AuthenticationType
{
get { return "Sitecore Authentication"; }
}
public bool IsAuthenticated
{
get { return Sitecore.Context.IsLoggedIn; }
}
}
public class AspnetUserSetter
{
public void Process(PipelineArgs args)
{
HttpContext.Current.User = new SitecorePrincipal();
}
}