Archive

Archive for March, 2008

SPRSS

March 30th, 2008 No comments

No, don’t read it SSRS (good old days :)) . It is called SPRSS and it is a fantastic , security-trimmed content Aggregator that my pal , Sahil Malik, has developed and released to the public in the codeplex. SPRSS comes in two main flavors :

1) CleanRSS.aspx: It can be replaced the ootb listfeed.aspx (http://yoursite/_layouts/listfeed.aspx) to extract much cleaner and XSLT friendly RSS feeds.

2) RSSWebPart: It can aggregate multiple RSS feeds across site collections, web apps and farms (and maybe in the future releases across our globe and milky galaxy ;)) into one security-aware bucket with the ability of applying XSLT to it.

Here are a couple of interesting usage scenarios for SPRSS.
Here is a good overview and future plans.
Here is a usage guide.

And FINALLY here is the codeplex project – http://www.codeplex.com/SPRSS

Categories: MOSS 2007 Tags:

Guest Account Enabler – Code Download and more!

March 30th, 2008 45 comments

Almost two months ago , I wrote three blog posts (part1,part 2 and part 3) about Anonymous Users In SharePoint, how to set it up ,challenges you might face dealing with these creatures and couple of solutions. Since then , I have received quite a few emails from people asking for two main things :

1) The source code for the solution I provided in part 3.

2) If there is any way to NOT use global.asax in a farm installation where there are multiple WFEs sitting behind a load balancer. In this case , the feature responsible for copying the global.asax file from the feature folder to the root folder of your SharePoint web application (hosted in IIS) only copies the global.asax to the WFE server on which you activate the feature. For the rest of WFEs , you need to manually replace the global.asax files. Not acceptable! Actually I am covering this issue in more details in my upcoming post : The Importance of Network Load Balancing.

Please download the source code from the link below. Take a look at the two projects included in the download.

Source Code
 

This download contains two folders:

I) GuestAccountEnabler_GlobalASAX

This folder contains the source code for “Guest Account Enabler” functionality as a feature scoped at a site collection. The fact that it is a site collection feature might introduce some permission issues (read the comments at FeatureActivated and FeatureDeactivating methods) wen using global.asax approach. Good news is that nothing prevents you to change the scope of the feature to Farm or WebApplication or run the code in FeatureActivated and FeatureDeactivating methods in an elevated context to make sure that activation and deactivation methods are executed with required access level to the file system. Bottom line is , it is not a fully automated approach for Farm installation. Please make sure you also read the ReadMe.txt for configuration steps.

II) GuestAccountEnabler_HttpHandler

To overcome the issues mentioned above , I went a head and implemented the Guest Account Enabler functionality in a Http Module. Remember, global.asax is just a specialized Http Module , but by placing our code into a Http module instead , it is much easier to share it between multiple Web applications plus it introduces much easier deployment in a farm installation. Our Http module sits on the top of the Http Request and check the authentication cookie , if It is not presented and the feature is enabled it injects the virtual “Guest” account into the current request and forces a new http request (reentering the http pipeline) to pick up the new [virtual] Forms identity. Please remember to read the ReadMe.txt file for configuration steps spscific for Http Module approach. Here is the gist of it:

  1. public class GuestModule : IHttpModule
  2.     {
  3.         public virtual void Init(HttpApplication context)
  4.         {
  5.             // Subscribe to events.
  6.             context.AuthenticateRequest += new EventHandler(context_AuthenticateRequest);
  7.         }
  8.         void context_AuthenticateRequest(object sender, EventArgs e)
  9.         {
  10.             OnAuthenticateRequest(((HttpApplication)sender).Context);
  11.         }
  12.         public virtual void Dispose(){}
  13.         /// <summary>
  14.         /// Authenticates the authorization request.
  15.         /// </summary>
  16.         private void OnAuthenticateRequest(HttpContext context)
  17.         {
  18.             if (context == null)
  19.                 throw new ArgumentNullException("context");
  20.             //Extract the forms authentication cookie
  21.             string cookieName = FormsAuthentication.FormsCookieName;
  22.             HttpCookie authCookie = context.Request.Cookies[cookieName];
  23.             if (null == authCookie)
  24.             {
  25.                 // There is no authentication cookie. Check to see if Guest Account feature is activated
  26.                 // If Feature is Activated, ValidateUser would return Guest Account Context
  27.                 if (Membership.ValidateUser("Guest", ""))
  28.                 {
  29.                     string requestedUrl = Uri.UnescapeDataString(context.Request.Url.ToString());
  30.                     FormsAuthentication.SetAuthCookie("Guest", false);
  31.                     //Force a new request (reenter the http pipeline)
  32.                     context.Response.Redirect(requestedUrl);
  33.                 }
  34.             }
  35.         }
  36.     }

As described in the ReadMe.txt , you need to register this Http Module in your extended site (the one that is protected by FBA). The good thing about this approach is that AuthenticateRequest event receiver only gets executed for your FBA site and only when the authentication cookie is not presented. That’s pretty much all about it !

Wait! I have included two more things in the download files.

1) It is no biggie , but you can see how to localize a feature’s title and description.
2) Have you ever heard about Minimal master page or minimal site definition (I wish there was one 😉 ) ? Both projects have a dummy Membership provider which I have called it “Minimal Membership Provider”. Well, eventually you will have to merge the Guest Account Enabler functionality into your existing membership provider , but to start with, you needed an authentication provider , right? I created that provider to give you the ability to quickly test the sample code. It is also using a dummy connection string so don’t even need to bother changing it to match your environment. Just put them in your Web.config and that’s it!

Categories: MOSS 2007 Tags: