Sitecore CMS and everything related RSS 2.0
 Wednesday, April 19, 2006
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();
   }
}
Wednesday, April 19, 2006 9:41:41 AM (FLE Standard Time, UTC+02:00)  #    Comments [0]
Sitecore | Security
Comments are closed.
Archive
<March 2010>
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
Blogroll
 Alex de Groot
Few words about SiteCore from Holland
 Alexander Shyba
Sitecore Support
 Anders Dreyer
Anders Dreyer on Sitecore Development
 Jakob Christensen
Sitecore Core Development
 Lars Fløe Nielsen
Lars's ramblings about development and business processes
 Ole Thrane
Sitecore API
 Runi Thomsen
Runi Thomsen Sitecore Toughts
 The Sitecore Experience
The Sitecore Experience
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010
Alexey Rusakov
Sign In
Statistics
Total Posts: 211
This Year: 0
This Month: 0
This Week: 0
Comments: 0
Themes
Pick a theme:
All Content © 2010, Alexey Rusakov
DasBlog theme 'Business' created by Christoph De Baene (delarou)