<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Brian Pedersen's Sitecore and .NET Blog</title>
	<atom:link href="http://briancaos.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://briancaos.wordpress.com</link>
	<description>A developer oriented blog about Sitecore, C#, ASP.NET and web related issues</description>
	<lastBuildDate>Thu, 09 Jul 2009 07:40:27 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
		<url>http://www.gravatar.com/blavatar/b5bdd911cc2b5b39af2e0cd5eb9af380?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Brian Pedersen's Sitecore and .NET Blog</title>
		<link>http://briancaos.wordpress.com</link>
	</image>
			<item>
		<title>Adding a file to the Sitecore Media Library programatically</title>
		<link>http://briancaos.wordpress.com/2009/07/09/adding-a-file-to-the-sitecore-media-library-programatically/</link>
		<comments>http://briancaos.wordpress.com/2009/07/09/adding-a-file-to-the-sitecore-media-library-programatically/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 07:39:08 +0000</pubDate>
		<dc:creator>briancaos</dc:creator>
				<category><![CDATA[Sitecore 5]]></category>
		<category><![CDATA[Sitecore 6]]></category>
		<category><![CDATA[media library]]></category>
		<category><![CDATA[MediaCreator]]></category>
		<category><![CDATA[MediaCreatorOptions]]></category>
		<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://briancaos.wordpress.com/?p=392</guid>
		<description><![CDATA[I thought it was tricky to read a file from disk and add it to the Sitecore media library untill I actually look into it. Sitecore has introduced 2 classes to help with the creation: The Sitecore.Resources.Media.MediaCreator and the Sitecore.Resources.Media.MediaCreatorOptions. 
The Sitecore.Resources.Media.MediaCreatorOptions class is the real gem here, as it helps you pick the right database to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=392&subd=briancaos&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I thought it was tricky to read a file from disk and add it to the <a href="http://www.sitecore.net" target="_blank">Sitecore</a> media library untill I actually look into it. Sitecore has introduced 2 classes to help with the creation: The <strong>Sitecore.Resources.Media.MediaCreator</strong> and the <strong>Sitecore.Resources.Media.MediaCreatorOptions</strong>. </p>
<p>The <strong>Sitecore.Resources.Media.MediaCreatorOptions </strong>class is the real gem here, as it helps you pick the right database to write to, but it also creates the folders where the file must be placed. In other words; don&#8217;t worry about creating folder items yourself. Let the MediaCreatorOptions do that for you. Here is an example:</p>
<pre name="code" class="csharp">

public MediaItem AddFile(string fileName, string sitecorePath, string mediaItemName)
{
  // Create the options
  Sitecore.Resources.Media.MediaCreatorOptions options = new Sitecore.Resources.Media.MediaCreatorOptions();
  // Store the file in the database, not as a file
  options.FileBased = false;
  // Remove file extension from item name
  options.IncludeExtensionInItemName = false;
  // Overwrite any existing file with the same name
  options.KeepExisting = false;
  // Do not make a versioned template
  options.Versioned = false;
  // set the path
  options.Destination = sitecorePath + &quot;/&quot; + mediaItemName; 
  // Set the database
  options.Database = Sitecore.Configuration.Factory.GetDatabase(&quot;master&quot;);

  // Now create the file
  Sitecore.Resources.Media.MediaCreator creator = new Sitecore.Resources.Media.MediaCreator();
  MediaItem mediaItem = creator.CreateFromFile(&quot;c:\\myfile.pdf&quot;, options);
  return mediaItem;
}
</pre>
<p>This exampel inserts the <strong>myfile.pdf</strong> into the media library and stores it as <strong>/pdffolder/uploaded/myfile</strong>:</p>
<pre name="code" class="csharp">
MediaItem myFile = AddFile(&quot;c:\\myfile.pdf&quot;, &quot;myfile&quot;, &quot;/pdffolder/uploaded&quot;);
</pre>
<p>The MediaCreator is also available through the static implementation, <strong>Sitecore.Resources.Media.MediaManager.Creator</strong>, so if you like statics, you can use that one instead.</p>
<p>The MediaCreator can also create media files from a <a href="http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx" target="_blank">MemoryStream</a>:</p>
<pre name="code" class="csharp">

// Remember to insert the appropriate try..catch..finally blocks.
// I have refrained from using them to compress the example.
Sitecore.Resources.Media.MediaCreatorOptions options = new Sitecore.Resources.Media.MediaCreatorOptions();
// Now use the options class as I did in the previous example
// ... insert code here ...
// ...
// Read the file from stream:
FileInfo fi = new System.IO.FileInfo(fileName);
FileStream fs = fi.OpenRead();
MemoryStream ms = new MemoryStream();
ms.SetLength(fs.Length);
fs.Read(ms.GetBuffer(), 0, (int)fs.Length);
ms.Flush();
fs.Close();
// Now create the file in Sitecore. This time I&#039;ll use the static implementation of the MediaCreator
Item mediaItem = Sitecore.Resources.Media.MediaManager.Creator.CreateFromStream(ms, fileName, options);
ms.Dispose();
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/briancaos.wordpress.com/392/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/briancaos.wordpress.com/392/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/briancaos.wordpress.com/392/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/briancaos.wordpress.com/392/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/briancaos.wordpress.com/392/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/briancaos.wordpress.com/392/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/briancaos.wordpress.com/392/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/briancaos.wordpress.com/392/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/briancaos.wordpress.com/392/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/briancaos.wordpress.com/392/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=392&subd=briancaos&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://briancaos.wordpress.com/2009/07/09/adding-a-file-to-the-sitecore-media-library-programatically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/25db0dbe9728e65c205cb902b4aa9741?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">briancaos</media:title>
		</media:content>
	</item>
		<item>
		<title>Waiting for gg.google.com</title>
		<link>http://briancaos.wordpress.com/2009/07/01/waiting-for-gg-google-com/</link>
		<comments>http://briancaos.wordpress.com/2009/07/01/waiting-for-gg-google-com/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 09:25:43 +0000</pubDate>
		<dc:creator>briancaos</dc:creator>
				<category><![CDATA[General .NET]]></category>
		<category><![CDATA[Firebug]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[gg.google.com]]></category>
		<category><![CDATA[Google maps]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://briancaos.wordpress.com/?p=387</guid>
		<description><![CDATA[I am developing a Google Maps module for Sitecore, and when I test it in Firefox my Google Javascript won&#8217;t load. All I get is: &#8220;Waiting for gg.google.com&#8230;&#8221;.
It seemes to be a problem with certain versions of Firefox and Firebug. If Firebug has Script debugging enabled, the Google Maps script will not load.
Disabling Script debugging in Firebug solves [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=387&subd=briancaos&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I am developing a <a href="http://maps.google.com/" target="_blank">Google Maps</a> module for <a href="http://www.sitecore.net" target="_blank">Sitecore</a>, and when I test it in <a href="http://www.mozilla-europe.org/en/firefox/" target="_blank">Firefox</a> my Google Javascript won&#8217;t load. All I get is: &#8220;Waiting for gg.google.com&#8230;&#8221;.</p>
<div id="attachment_388" class="wp-caption aligncenter" style="width: 325px"><a href="http://briancaos.files.wordpress.com/2009/07/gg_waiting.jpg"><img class="size-full wp-image-388" title="Waiting for gg.google.com" src="http://briancaos.files.wordpress.com/2009/07/gg_waiting.jpg?w=315&#038;h=65" alt="Waiting for gg.google.com" width="315" height="65" /></a><p class="wp-caption-text">Waiting for gg.google.com</p></div>
<p>It seemes to be a problem with <a href="http://groups.google.com/group/Google-Maps-API/browse_thread/thread/68218c6665dd527e" target="_blank">certain versions</a> of Firefox and <a href="http://getfirebug.com/" target="_blank">Firebug</a>. If Firebug has Script debugging enabled, the Google Maps script will not load.</p>
<p>Disabling Script debugging in Firebug solves the problem:</p>
<div id="attachment_389" class="wp-caption aligncenter" style="width: 610px"><a href="http://briancaos.files.wordpress.com/2009/07/gg_disable.jpg"><img class="size-medium wp-image-389" title="Disable Script Debugging in Firebug" src="http://briancaos.files.wordpress.com/2009/07/gg_disable.jpg?w=600" alt="Disable Script Debugging in Firebug" width="600" /></a><p class="wp-caption-text">Disable Script Debugging in Firebug</p></div>
<p>But now I cannot debug the Javascript I am creating using Firefox. Well&#8230; I&#8217;m glad I got <a href="http://www.google.com/chrome" target="_blank">Google Chrome</a>.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/briancaos.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/briancaos.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/briancaos.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/briancaos.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/briancaos.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/briancaos.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/briancaos.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/briancaos.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/briancaos.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/briancaos.wordpress.com/387/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=387&subd=briancaos&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://briancaos.wordpress.com/2009/07/01/waiting-for-gg-google-com/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/25db0dbe9728e65c205cb902b4aa9741?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">briancaos</media:title>
		</media:content>

		<media:content url="http://briancaos.files.wordpress.com/2009/07/gg_waiting.jpg" medium="image">
			<media:title type="html">Waiting for gg.google.com</media:title>
		</media:content>

		<media:content url="http://briancaos.files.wordpress.com/2009/07/gg_disable.jpg?w=600" medium="image">
			<media:title type="html">Disable Script Debugging in Firebug</media:title>
		</media:content>
	</item>
		<item>
		<title>Controlling YetAnotherForum from inside Sitecore</title>
		<link>http://briancaos.wordpress.com/2009/06/10/controlling-yetanotherforum-from-inside-sitecore/</link>
		<comments>http://briancaos.wordpress.com/2009/06/10/controlling-yetanotherforum-from-inside-sitecore/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 09:11:03 +0000</pubDate>
		<dc:creator>briancaos</dc:creator>
				<category><![CDATA[Sitecore 6]]></category>
		<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[YAF]]></category>
		<category><![CDATA[YAFIntegration]]></category>
		<category><![CDATA[YetAnotherForum]]></category>

		<guid isPermaLink="false">http://briancaos.wordpress.com/?p=324</guid>
		<description><![CDATA[One of my recent projects has been to run YetAnotherForum (YAF) inside a Sitecore website (read this earlier post). The changed YAF source can be found as an open source project at http://trac.sitecore.net/YAFIntegration.
Now the project has been expanded with a Sitecore package that allows you to control the behaviour of the YAF control from inside Sitecore. The optional [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=324&subd=briancaos&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>One of my recent projects has been to run <a href="http://www.yetanotherforum.net" target="_blank">YetAnotherForum</a> (YAF) inside a <a href="http://www.sitecore.net" target="_blank">Sitecore</a> website (<a href="http://briancaos.wordpress.com/2009/05/28/running-yetanotherforum-inside-sitecore/" target="_blank">read this earlier post</a>). The changed YAF source can be found as an open source project at <a href="http://trac.sitecore.net/YAFIntegration">http://trac.sitecore.net/YAFIntegration</a>.</p>
<p>Now the project has been expanded with a Sitecore package that allows you to control the behaviour of the YAF control from inside Sitecore. The optional package consists of a custom field and a sublayout that allows you to set which board, group or forum that YAF should display.</p>
<p>When placing the custom field on a page, it becomes possible to select which board, group or forum that the sublayout must display:</p>
<div id="attachment_325" class="wp-caption aligncenter" style="width: 451px"><a href="http://briancaos.files.wordpress.com/2009/06/yafcustomfield.jpg"><img class="size-full wp-image-325" title="YAF Custom Field" src="http://briancaos.files.wordpress.com/2009/06/yafcustomfield.jpg?w=441&#038;h=189" alt="Displaying boards, groups and forums from YAF" width="441" height="189" /></a><p class="wp-caption-text">Displaying boards, groups and forums from YAF</p></div>
<p>The sublayout uses this data to display whatever is chosen:</p>
<div id="attachment_326" class="wp-caption aligncenter" style="width: 310px"><a href="http://briancaos.files.wordpress.com/2009/06/yafforum.jpg"><img class="size-medium wp-image-326" title="YAF Forum" src="http://briancaos.files.wordpress.com/2009/06/yafforum.jpg?w=300&#038;h=258" alt="This example shows how YAF used the information from the dropdown to display one forum only." width="300" height="258" /></a><p class="wp-caption-text">This example shows how YAF used the information from the dropdown to display one forum only.</p></div>
<p>The function gives you the possibility to display one forum on one Sitecore page, and another forum on another page. Or displaying all forums on one page, one group on another page, and one forum on a third page. And so on and so on. </p>
<p>The feature is part of the optional Sitecore package included in the <a href="http://trac.sitecore.net/YAFIntegration" target="_blank">YAFIntegration </a>project. Read more about the package here: <a href="http://trac.sitecore.net/YAFIntegration/wiki/Optional_Package">http://trac.sitecore.net/YAFIntegration/wiki/Optional_Package</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/briancaos.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/briancaos.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/briancaos.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/briancaos.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/briancaos.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/briancaos.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/briancaos.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/briancaos.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/briancaos.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/briancaos.wordpress.com/324/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=324&subd=briancaos&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://briancaos.wordpress.com/2009/06/10/controlling-yetanotherforum-from-inside-sitecore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/25db0dbe9728e65c205cb902b4aa9741?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">briancaos</media:title>
		</media:content>

		<media:content url="http://briancaos.files.wordpress.com/2009/06/yafcustomfield.jpg" medium="image">
			<media:title type="html">YAF Custom Field</media:title>
		</media:content>

		<media:content url="http://briancaos.files.wordpress.com/2009/06/yafforum.jpg?w=300" medium="image">
			<media:title type="html">YAF Forum</media:title>
		</media:content>
	</item>
		<item>
		<title>Running YetAnotherForum inside Sitecore</title>
		<link>http://briancaos.wordpress.com/2009/05/28/running-yetanotherforum-inside-sitecore/</link>
		<comments>http://briancaos.wordpress.com/2009/05/28/running-yetanotherforum-inside-sitecore/#comments</comments>
		<pubDate>Thu, 28 May 2009 14:28:57 +0000</pubDate>
		<dc:creator>briancaos</dc:creator>
				<category><![CDATA[Sitecore 6]]></category>
		<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[YAF]]></category>
		<category><![CDATA[YAFIntegration]]></category>
		<category><![CDATA[YetAnotherForum]]></category>

		<guid isPermaLink="false">http://briancaos.wordpress.com/?p=313</guid>
		<description><![CDATA[As I mentioned in the previous post, YetAnotherForum (YAF) cannot run inside Sitecore unless the code base of YAF is changed. So that&#8217;s exactly what I did. 
 You can find the changed YAF codebase in Sitecores trac:
http://trac.sitecore.net/YAFIntegration
So what does the code do? It allows you to run YAF in a Sitecore layout, on any Sitecore page you wish, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=313&subd=briancaos&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>As I mentioned in the <a href="http://briancaos.wordpress.com/2009/05/27/using-sitecore-users-in-yetanotherforum/" target="_blank">previous post</a>, <a href="http://www.yetanotherforum.net" target="_blank">YetAnotherForum</a> (YAF) cannot run inside <a href="http://www.sitecore.net" target="_blank">Sitecore</a> unless the code base of YAF is changed. So that&#8217;s exactly what I did. </p>
<div id="attachment_314" class="wp-caption aligncenter" style="width: 410px"><a href="http://briancaos.files.wordpress.com/2009/05/yaf01.jpg"><img class="size-thumbnail wp-image-314 " title="YetAnotherForum inside Sitecore" src="http://briancaos.files.wordpress.com/2009/05/yaf01.jpg?w=400&#038;h=338" alt="YetAnotherForum running in Sitecore" width="400" height="338" /></a><p class="wp-caption-text">YetAnotherForum running in Sitecore</p></div>
<p> You can find the changed YAF codebase in Sitecores trac:</p>
<p style="text-align:center;"><a href="http://trac.sitecore.net/YAFIntegration">http://trac.sitecore.net/YAFIntegration</a></p>
<p style="text-align:left;">So what does the code do? It allows you to run YAF in a Sitecore layout, on any Sitecore page you wish, using Sitecore extranet (or any other domain) users.</p>
<p style="text-align:left;">But let&#8217;s begin with the beginning. In order to run YAF inside a Sitecore web site at all, <strong>major changes are required in the web.config of your website</strong>. Basically it requires you to merge the YAF config files with the Sitecore config files. I have provided a <a href="http://trac.sitecore.net/YAFIntegration/browser/Trunk/YetAnotherForum.NET/webconfigs/sitecore.web.config" target="_blank">sample web.config</a> where I have merged the 2 config files together, as well as a <a href="http://trac.sitecore.net/YAFIntegration/browser/Trunk/YAF%20Integrated%20into%20Sitecore.docx" target="_blank">complete description of all changes required</a>.</p>
<p style="text-align:left;">After you have merged the web.configs, you will need to build the code and apply the code and binaries to the Sitecore solution. The <a href="http://trac.sitecore.net/YAFIntegration/browser/Trunk/YAF%20Integrated%20into%20Sitecore.docx" target="_blank">documentation</a> will help you with this.</p>
<p style="text-align:left;">What code changes have been made then? Since Sitecore and YAF both uses <a href="http://msdn.microsoft.com/en-us/magazine/cc163807.aspx" target="_blank">standard .net security providers</a>, changes are relatively small (although widespread). YAF is capable of digesting Sitecore members and roles (users and groups) directly. But since the .net platform only allows one <a href="http://msdn.microsoft.com/en-us/library/0580x1f5.aspx" target="_blank">profile provider</a>, the YAF profile provider need to inherit from Sitecore&#8217;s profile.</p>
<p style="text-align:left;">Another change are also implemented: The standard .net security model expects all users to have access to all parts of the website. Sitecore cannot live with that, as some users can access the client, and other can access the extranet. Sitecore deals with this issue in a brilliant, simple way, by prefixing users with the Sitecore domain name. So when Sitecore returns the Anonymous user, the username is <strong>extranet\Anonymous</strong>. To avoid displaying user names prefixed with the current domain name in YAF, the code wraps the <a href="http://msdn.microsoft.com/en-us/library/system.web.security.membershipuser.aspx" target="_blank">MembershipUser </a>class to ensure that only users from the current domain (usually <strong>extranet</strong>) can log into YAF, and that the domain name is not displayed in the username.</p>
<div id="attachment_316" class="wp-caption aligncenter" style="width: 510px"><a href="http://briancaos.files.wordpress.com/2009/05/yafusers.jpg"><img class="size-medium wp-image-314" title="Sitecore users in YAF" src="http://briancaos.files.wordpress.com/2009/05/yafusers.jpg?w=500" alt="Users from the current Sitecore domain is displayed in YAF." width="500" /></a><p class="wp-caption-text">Users from the current Sitecore domain is displayed in YAF.</p></div>
<p style="text-align:left;">Since YAF is licensed under the <a href="http://www.gnu.org/copyleft/gpl.html" target="_blank">GNU public license</a>, so is this code. This means that you can use, change and share the code and any changes you make, as you wish.</p>
<p style="text-align:left;"> </p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/briancaos.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/briancaos.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/briancaos.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/briancaos.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/briancaos.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/briancaos.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/briancaos.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/briancaos.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/briancaos.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/briancaos.wordpress.com/313/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=313&subd=briancaos&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://briancaos.wordpress.com/2009/05/28/running-yetanotherforum-inside-sitecore/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/25db0dbe9728e65c205cb902b4aa9741?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">briancaos</media:title>
		</media:content>

		<media:content url="http://briancaos.files.wordpress.com/2009/05/yaf01.jpg?w=400" medium="image">
			<media:title type="html">YetAnotherForum inside Sitecore</media:title>
		</media:content>

		<media:content url="http://briancaos.files.wordpress.com/2009/05/yafusers.jpg?w=500" medium="image">
			<media:title type="html">Sitecore users in YAF</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Sitecore users in YetAnotherForum</title>
		<link>http://briancaos.wordpress.com/2009/05/27/using-sitecore-users-in-yetanotherforum/</link>
		<comments>http://briancaos.wordpress.com/2009/05/27/using-sitecore-users-in-yetanotherforum/#comments</comments>
		<pubDate>Wed, 27 May 2009 11:15:24 +0000</pubDate>
		<dc:creator>briancaos</dc:creator>
				<category><![CDATA[Sitecore 6]]></category>
		<category><![CDATA[Single signon]]></category>
		<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[YAF]]></category>
		<category><![CDATA[YetAnotherForum]]></category>

		<guid isPermaLink="false">http://briancaos.wordpress.com/?p=305</guid>
		<description><![CDATA[YetAnotherForum (or YAF for short) is an open source discussion forum written in C# and .NET. Sitecore and YAF cannot run in the same IIS application (they can, if you change the YAF source code, which I will show in a later post), but with a little piece of open source code you are able [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=305&subd=briancaos&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://www.yetanotherforum.net/" target="_blank">YetAnotherForum </a>(or YAF for short) is an open source discussion forum written in C# and .NET. <a href="http://www.sitecore.net" target="_blank">Sitecore </a>and YAF cannot run in the same <a href="http://www.developer.com/net/asp/article.php/2245511" target="_blank">IIS application</a> (they can, if you change the YAF source code, which I will show in a <a href="http://briancaos.wordpress.com/2009/05/28/running-yetanotherforum-inside-sitecore/" target="_blank">later post</a>), but with a little piece of open source code you are able to use the Sitecore users in YAF.</p>
<p>The open source code is available at:</p>
<p style="text-align:center;"><a href="http://trac.sitecore.net/SitecoreYAF">http://trac.sitecore.net/YAFSingleSignon</a></p>
<p>The idea is to have Sitecore and YAF running in the same second-level domains: For example let your Sitecore website run at <strong>www.mysite.com</strong> and YAF in <strong>forum.mysite.com</strong>.<br />
When users log into the Sitecore extranet, the user information is stored in a cookie which is then digested by YAF.</p>
<p>First you will need to download the code from <a href="http://trac.sitecore.net/SitecoreYAF">http://trac.sitecore.net/YAFSingleSignon</a> and build it yourself.</p>
<p>Copy the <strong>YAFLogin.dll</strong> to your Sitecore <strong>/bin/</strong> folder. Then copy the <strong>YAFLogin.dll</strong> and <strong>SitecoreLogin.dll</strong> to the YAF <strong>/bin/</strong> folder. Also copy the <strong>/sitecorelogin/default.aspx</strong> page to YAF.</p>
<p>In order to save the extranet credentials, you must apply the following 2 lines of code to your Sitecore extranet login dialog:</p>
<pre name="code" class="csharp">
// Create a SitecoreUser by logging into the Sitecore extranet
// and retrieve the user information
SitecoreUser user = SitecoreUser.Login(eUserName.Text, ePassword.Text, chkRememberMe.Checked);
// Store the SitecoreUser as a cookie. This cookie can be retrieved by YAF.
user.Store();
</pre>
<p>That’s it. The user information is persisted in a cookie which can be digested by YAF, as <a href="http://www.15seconds.com/issue/971108.htm" target="_blank">cookies can be shared across second-level domains</a>. There are 2 methods of digesting the Sitecore extranet user. The first method is to call the <strong>/sitecorelogin/default.aspx</strong> page which will create the user in YAF (if not already existing) do a login a redirect to the default YAF page. The second method is to extend the default.aspx page of YAF with the following code:</p>
<pre name="code" class="csharp">
protected void Page_Load(object sender, EventArgs e)
{
  try
  {
    // Restore the sitecore user from the persistant storage (the cookie)
    YAF.Sitecore.PersistenceManager manager = new YAF.Sitecore.PersistenceManager();
    YAF.Sitecore.SitecoreUser user = manager.Restore();
    if (user != null)
    {
      // Instantiate the login manager and log the Sitecore user into YAF
      YAF.Sitecore.LoginManager loginManager = new YAF.Sitecore.LoginManager();
      loginManager.Login(user);
      // The SitecoreUser is now logged in, and the cookie can be removed
      manager.Delete();
      // Load same page to let YAF read the session
      Response.Redirect(Request.RawUrl,false);
    }
  }
  catch (Exception ex)
  {
    Response.Write(&quot;Failed to login Sitecore Extranet user: &quot; + ex.Message);
  }
}
</pre>
<p>This code does the same as the /sitecorelogin/default.aspx but will be executed by every page in YAF you call.</p>
<p>You can read more about the source code at <a href="http://trac.sitecore.net/YAFSingleSignon/browser/Trunk/Sitecore.YAF.docx">http://trac.sitecore.net/YAFSingleSignon/browser/Trunk/Sitecore.YAF.docx</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/briancaos.wordpress.com/305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/briancaos.wordpress.com/305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/briancaos.wordpress.com/305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/briancaos.wordpress.com/305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/briancaos.wordpress.com/305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/briancaos.wordpress.com/305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/briancaos.wordpress.com/305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/briancaos.wordpress.com/305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/briancaos.wordpress.com/305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/briancaos.wordpress.com/305/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=305&subd=briancaos&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://briancaos.wordpress.com/2009/05/27/using-sitecore-users-in-yetanotherforum/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/25db0dbe9728e65c205cb902b4aa9741?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">briancaos</media:title>
		</media:content>
	</item>
		<item>
		<title>Check whether client&#8217;s browser have cookies enabled</title>
		<link>http://briancaos.wordpress.com/2009/05/11/check-whether-clients-browser-have-cookies-enabled/</link>
		<comments>http://briancaos.wordpress.com/2009/05/11/check-whether-clients-browser-have-cookies-enabled/#comments</comments>
		<pubDate>Mon, 11 May 2009 11:26:57 +0000</pubDate>
		<dc:creator>briancaos</dc:creator>
				<category><![CDATA[General .NET]]></category>
		<category><![CDATA[Sitecore 5]]></category>
		<category><![CDATA[Sitecore 6]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[cookiedetect]]></category>

		<guid isPermaLink="false">http://briancaos.wordpress.com/?p=296</guid>
		<description><![CDATA[Usually we assume that every user have cookies enabled. I cannot find any stats on the number of users who have disabled cookies, but 94% of all browsers have Javascript enabled, so lets assume that en equal number have cookies enabled (I know that the remaining 6% could easily be web crawlers).
What should we do [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=296&subd=briancaos&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Usually we assume that every user have <a href="http://en.wikipedia.org/wiki/HTTP_cookie" target="_blank">cookies </a>enabled. I cannot find any stats on the number of users who have disabled cookies, but <a href="http://www.thecounter.com/stats/2009/March/javas.php" target="_blank">94% of all browsers have Javascript enabled</a>, so lets assume that en equal number have cookies enabled (I know that the remaining 6% could easily be web crawlers).</p>
<p>What should we do with the remaining 6% then? If the website uses cookies as a shopping basket, it would be a good service to let the user know that he is not able to shop without enabling cookies.</p>
<p>When first investigatig this, I assumed that a server-side solution existed. So I implemented the following code in c#:</p>
<pre name="code" class="csharp">
if (Request.Browser.Cookies) 
  Response.Write(&quot;Your browser supports cookies. You may shop&quot;);
else
  Response.Write(&quot;The Browser does not support Cookies. Shopping is not possible.&quot;);
</pre>
<p>Unfortunately this tells me if the browser <strong>as such</strong> supports cookies, not that cookies are enabled by the user. When using IE7, the code always returns true, since IE7 supports cookies in general. Disabling cookies in IE7 changes nothing.</p>
<p>I used <a href="http://www.google.dk/search?hl=da&amp;safe=off&amp;q=determining+cookie+support&amp;meta=" target="_blank">Google </a>to search for the answer, and unfortunately you need to use <a href="http://en.wikipedia.org/wiki/Javascript" target="_blank">Javascript </a>to check if the user have enabled cookies in his browser. <a href="http://wsabstract.com/javatutors/cookiedetect.shtml" target="_blank">This website contains the Javascript to use</a>.</p>
<p>I rewrote the Javascript so it writes some text if cookies are enabled, and another text if not:</p>
<pre name="code" class="javascript">
function CookieSetText(yesText, noText)
{
  var cookieEnabled=(navigator.cookieEnabled)? true : false
  //if not IE4+ nor NS6+
  if (typeof navigator.cookieEnabled==&quot;undefined&quot; &amp;amp;amp;&amp;amp;amp; !cookieEnabled)
  {
    document.cookie=&quot;testcookie&quot;
    cookieEnabled=(document.cookie.indexOf(&quot;testcookie&quot;)!=-1)? true : false
  }
  if (cookieEnabled)
    document.write(yesText);
  else
    document.write(noText);
}
</pre>
<p> When adding a reference to the script in my HTML header, I can use it from my <a href="http://www.sitecore.net" target="_blank">Sitecore</a> XSLT&#8217;s:</p>
<pre name="code" class="xml">
&lt;script type=&quot;text/javascript&quot;&gt;
  CookieSetText(&#039;&lt;sc:text field=&quot;CookiesEnabled&quot;/&gt;&#039;, &#039;&lt;sc:text field=&quot;CookiesDisabled&quot;/&gt;&#039;);
&lt;/script&gt;
</pre>
<p>Th example above writes the text for the current item&#8217;s &#8220;CookiesEnabled&#8221; field if cookies are enabled, or writes from the &#8220;CookiesDisabled&#8221; field when cookies are disabled.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/briancaos.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/briancaos.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/briancaos.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/briancaos.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/briancaos.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/briancaos.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/briancaos.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/briancaos.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/briancaos.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/briancaos.wordpress.com/296/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=296&subd=briancaos&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://briancaos.wordpress.com/2009/05/11/check-whether-clients-browser-have-cookies-enabled/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/25db0dbe9728e65c205cb902b4aa9741?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">briancaos</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating a tree like left menu in Sitecore using XSLT</title>
		<link>http://briancaos.wordpress.com/2009/04/24/creating-a-tree-like-left-menu-in-sitecore-using-xslt/</link>
		<comments>http://briancaos.wordpress.com/2009/04/24/creating-a-tree-like-left-menu-in-sitecore-using-xslt/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 11:49:09 +0000</pubDate>
		<dc:creator>briancaos</dc:creator>
				<category><![CDATA[Sitecore 5]]></category>
		<category><![CDATA[Sitecore 6]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[XSLT]]></category>

		<guid isPermaLink="false">http://briancaos.wordpress.com/?p=282</guid>
		<description><![CDATA[This is one of my oldest tricks in my book. The tree-like left menu is used for almost any website I do, and will work like on this site (example site is not developed by me nor by Pentia). This image is from a website using the menu:
The XSLT renders a multilevel left menu, usually placed on pages on websites utilizing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=282&subd=briancaos&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>This is one of my oldest tricks in my book. The tree-like left menu is used for almost any website I do, and will work <a href="http://www.naestved.dk/ServiceBorgere.aspx" target="_blank">like on this site</a> (example site is not developed by me nor by <a href="http://www.pentia.dk" target="_blank">Pentia</a>). This image is from a website using the menu:</p>
<div id="attachment_289" class="wp-caption aligncenter" style="width: 310px"><a href="http://briancaos.files.wordpress.com/2009/04/menuexample1.jpg"><img class="size-medium wp-image-289" title="Menu Example" src="http://briancaos.files.wordpress.com/2009/04/menuexample1.jpg?w=300&#038;h=172" alt="Sample Menu" width="300" height="172" /></a><p class="wp-caption-text">Sample Menu</p></div>
<p>The XSLT renders a multilevel left menu, usually placed on pages on websites utilizing a sectional top menu. The menu will fold out any subitems below the current page, and will display the entire tree structure from the current page and upwards to the sectional page that the left menu is placed under.</p>
<p>In this simplified example I use pages with the menu title placed in the field <strong>Menu_Title</strong>, and I use a checkbox called <strong>Show_In_Menu</strong> to hide items that is not to be shown in the left menu.</p>
<p>The left menu is initialized with the current section page that will act as the root item for the menu. If you use the home page as your section item it will render the complete web site.</p>
<pre name="code" class="xml">
&lt;xsl:template match=&quot;*&quot; mode=&quot;main&quot;&gt;
  &lt;!-- Get the root item --&gt;
  &lt;xsl:variable name=&quot;section&quot; select=&quot;ancestor-or-self::item[@id = $home/item/@id]&quot;/&gt;
  &lt;!-- Render the menu from the root item and downwards --&gt;
  &lt;xsl:call-template name=&quot;renderMenu&quot;&gt;
    &lt;xsl:with-param name=&quot;root&quot; select=&quot;$section&quot;/&gt;
    &lt;xsl:with-param name=&quot;level&quot; select=&quot;0&quot;/&gt;
    &lt;xsl:with-param name=&quot;items&quot; select=&quot;$section/item[sc:fld(&#039;Show_In_Menu&#039;,.) = &#039;1&#039;]&quot;/&gt;
  &lt;/xsl:call-template&gt;
&lt;/xsl:template&gt;
</pre>
<p>Parameter <strong>root</strong> identifies the root item of the menu. <strong>Level</strong> is used for styling the menu (if you use different styles for the different levels). <strong>Items</strong> is a list of all items below the root item the must be rendered in the menu. In this example this includes all items where the field <strong>Show_In_Menu</strong> is checked.</p>
<p>The menu is rendered recursively by letting the <strong>renderMenu</strong> template call itself for each level it has to render.</p>
<pre name="code" class="xml">
&lt;xsl:template name=&quot;renderMenu&quot;&gt;
  &lt;xsl:param name=&quot;root&quot;/&gt;
  &lt;xsl:param name=&quot;level&quot;/&gt;
  &lt;xsl:param name=&quot;items&quot;/&gt;

  &lt;xsl:if test=&quot;$items&quot;&gt;
&lt;ul class=&quot;level{$level}&quot;&gt;
      &lt;xsl:for-each select=&quot;$items&quot;&gt;
        &lt;xsl:variable name=&quot;subItems&quot; select=&quot;item[sc:fld(&#039;Show_In_Menu&#039;,.) = &#039;1&#039;]&quot;/&gt;
	&lt;li&gt;
          &lt;!-- Apply CSS to the link --&gt;
          &lt;xsl:variable name=&quot;selectedClass&quot;&gt;
            &lt;!-- Item has children --&gt;
            &lt;xsl:if test=&quot;$subItems&quot;&gt;children&lt;/xsl:if&gt;
            &lt;!-- Item is open (one of it&#039;s children is the current page --&gt;
            &lt;xsl:if test=&quot;$subItems and @id = $selectedItem/ancestor-or-self::item/@id&quot;&gt; open&lt;/xsl:if&gt;
            &lt;!-- Item is the current page --&gt;
            &lt;xsl:if test=&quot;@id = $selectedItem/@id&quot;&gt; selected&lt;/xsl:if&gt;
          &lt;/xsl:variable&gt;

          &lt;!-- Write link including generated CSS tag --&gt;
          &lt;a href=&quot;{sc:path(.)}&quot; class=&quot;{$selectedClass}&quot;&gt;
            &lt;sc:text field=&quot;Menu_Title&quot;/&gt;           
          &lt;/a&gt;

          &lt;!-- Go further down the tree and render children --&gt;
          &lt;xsl:if test=&quot;@id = $selectedItem/ancestor-or-self::item/@id&quot;&gt;
            &lt;xsl:call-template name=&quot;renderMenu&quot;&gt;
              &lt;xsl:with-param name=&quot;root&quot; select=&quot;.&quot;/&gt;
              &lt;xsl:with-param name=&quot;level&quot; select=&quot;$level+1&quot;/&gt;
              &lt;xsl:with-param name=&quot;items&quot; select=&quot;$subItems&quot;/&gt;
            &lt;/xsl:call-template&gt;
          &lt;/xsl:if&gt;
       &lt;/li&gt;
      &lt;/xsl:for-each&gt;&lt;/ul&gt;
  &lt;/xsl:if&gt;
&lt;/xsl:template&gt;
</pre>
<p>The template renders all items of the first level, but second, third and later levesl are only rendered if the current page is found in that branch. This gives the menu its fold-out like behaviour.<br />
Please note how I style the menu link. The variable <strong>selectedClass</strong> is set with different content depending of the properties of the link to render. The example uses the three most commonly used styles applied: When the link has children, when the link has children, and the current page is one of these children and when the link is the current page.<br />
Yes, it&#8217;s that simple to do an advanced left menu in <a href="http://www.sitecore.net" target="_blank">Sitecore</a>. I have also done the same menu for <a href="http://umbraco.org/" target="_blank">Umbraco</a>, but that&#8217;s a different matter.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/briancaos.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/briancaos.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/briancaos.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/briancaos.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/briancaos.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/briancaos.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/briancaos.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/briancaos.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/briancaos.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/briancaos.wordpress.com/282/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=282&subd=briancaos&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://briancaos.wordpress.com/2009/04/24/creating-a-tree-like-left-menu-in-sitecore-using-xslt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/25db0dbe9728e65c205cb902b4aa9741?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">briancaos</media:title>
		</media:content>

		<media:content url="http://briancaos.files.wordpress.com/2009/04/menuexample1.jpg?w=300" medium="image">
			<media:title type="html">Menu Example</media:title>
		</media:content>
	</item>
		<item>
		<title>Using declarative security in Sitecore</title>
		<link>http://briancaos.wordpress.com/2009/04/01/using-declarative-security-in-sitecore/</link>
		<comments>http://briancaos.wordpress.com/2009/04/01/using-declarative-security-in-sitecore/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 10:59:51 +0000</pubDate>
		<dc:creator>briancaos</dc:creator>
				<category><![CDATA[Sitecore 5]]></category>
		<category><![CDATA[Sitecore 6]]></category>
		<category><![CDATA[declarative]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://briancaos.wordpress.com/?p=271</guid>
		<description><![CDATA[Writing XAML applications for use in the Sitecore shell can be very tricky. And I admit that I often decide to use a webform instead. Especially if I need to write a minor application that does not use Sitecore data as such, but still needs to be a part of the Sitecore desktop.
One of the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=271&subd=briancaos&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><div id="attachment_279" class="wp-caption alignright" style="width: 310px"><a href="http://briancaos.files.wordpress.com/2009/04/formsdataviewer.jpg"><img class="size-medium wp-image-279   " title="Forms Data Viewer" src="http://briancaos.files.wordpress.com/2009/04/formsdataviewer.jpg?w=300&#038;h=135" alt="Forms data viewer is one example of a webform in Sitecore" width="300" height="135" /></a><p class="wp-caption-text">The Forms data viewer is one example of a webform in Sitecore</p></div>
<p>Writing XAML applications for use in the <a href="http://www.sitecore.net" target="_blank">Sitecore </a>shell can be very tricky. And I admit that I often decide to <a href="http://sitecoresupport.blogspot.com/2008/12/how-to-bring-webform-to-sitecore.html" target="_blank">use a webform</a> instead. Especially if I need to write a minor application that does not use Sitecore data as such, but still needs to be a part of the Sitecore desktop.</p>
<div class="mceTemp">One of the downsides of using an .aspx page in the shell is (<em>besides the fact that the styling usually ends up being completely different from the Sitecore styling</em>) is that the application can be called from outside of the Shell context. This is especially a problem if the application is used in public websites, as everyone, including my web site visitors, will be able to execute the page, if they know the URL.</div>
<p>One of the solutions is to implement my own <a href="http://msdn.microsoft.com/en-us/library/system.security.principal.genericidentity.aspx" target="_blank">Generic Identity</a> and use <a href="http://msdn.microsoft.com/en-us/library/kaacwy28.aspx" target="_blank">declarative security</a> in my webform. And it&#8217;s quite easy too. This code can be expanded, but I have kept it simple to demonstrate the principals. Implementing yout own security context requires a <a href="http://msdn.microsoft.com/en-us/library/system.security.principal.genericidentity.aspx" target="_blank">generic identity</a> (a user) and a <a href="http://msdn.microsoft.com/en-us/library/system.security.principal.genericprincipal.aspx" target="_blank">generic principal</a> (a list of groups). The generic identity looks like this:</p>
<pre name="code" class="csharp">
using System.Security.Permissions;
using System.Collections.Generic;
using System.Threading;
using System.Security.Principal;

/// &lt;summary&gt;
/// Class imlementing a generic identity
/// which equals one Sitecore user
/// &lt;/summary&gt;
public class SitecoreIdentity : IIdentity
{
  private Sitecore.Security.Accounts.User _user;

  public SitecoreIdentity()
  {
    _user = Sitecore.Context.User; 
  }

  #region IIdentity Members

  public string AuthenticationType
  {
    // I cheat a little bit. Sitecore returns an empty AuthenticationType
    // so I use the domain name as authenticationtype instead
    get { return Sitecore.Context.Domain.Name; }
  }

  public bool IsAuthenticated
  {
    get { return _user.Identity.IsAuthenticated; }
  }

  public string Name
  {
    get { return _user.Name; }
  }

  #endregion
}
</pre>
<p>An identity is accompanied by a principal, which equals the roles that the identity (user) belongs to:</p>
<pre name="code" class="csharp">
/// &lt;summary&gt;
/// Class implementing a generic principal
/// which equals the groups one sitecore user
/// belongs to
/// &lt;/summary&gt;
public class SitecorePrincipal : IPrincipal
{
  private List&lt;string&gt; _roles = new List&lt;string&gt;();
  private IIdentity _identity;
  private Sitecore.Security.Accounts.User _user;

  public SitecorePrincipal(IIdentity identity)
  {
    _identity = identity;
    _user = Sitecore.Context.User; 
    // I add the administrator as a role to my principal so I can query it
    // when using declarative security
    if (Sitecore.Context.User.IsAdministrator)
      _roles.Add(&quot;Administrator&quot;);
    // Add all role names from the current user to my principal
    foreach (Sitecore.Security.Accounts.Role userRole in _user.Roles)
    {
      _roles.Add(userRole.Name);
    }
  }

  #region IPrincipal Members
  public IIdentity Identity { get { return _identity; } }
  public bool IsInRole(string role) { return _roles.Contains(role); }
  #endregion
}
</pre>
<p>I can now assign the current thread&#8217;s principal of the current webform to my own principal:</p>
<pre name="code" class="csharp">
void Page_Load(object sender, System.EventArgs e)
{
  // Create new user
  SitecoreIdentity user = new SitecoreIdentity();
  // Assign the roles to that user
  SitecorePrincipal roles = new SitecorePrincipal(user);
  // Assign the roles to the current thread
  Thread.CurrentPrincipal = roles;
}
</pre>
<p>My webform is now runing under the security context of my Sitecore user, and I can now use declarative security to allow or disallow execution of code. The following function will only execute if a Sitecore user is authenticated:</p>
<pre name="code" class="csharp">
[PrincipalPermission(SecurityAction.Demand, Authenticated=true)]
private void WriteText()
{
  Response.Write(&quot;Authentication: &quot; + Thread.CurrentPrincipal.Identity.AuthenticationType);
  Response.Write(&quot;Is authenticated: &quot; + Thread.CurrentPrincipal.Identity.IsAuthenticated);
  Response.Write(&quot;Name: &quot; + Thread.CurrentPrincipal.Identity.Name);
}
</pre>
<p>It is the <a href="http://msdn.microsoft.com/en-us/library/system.security.permissions.principalpermission.aspx" target="_blank">PrincipalPermission</a> attribute that sets the security on my function. If the current Sitecore user is not logged in, .net will throw an <a href="http://www.c-sharpcorner.com/UploadFile/rajeshvs/ExceptionHandlinginCSharp11282005051444AM/ExceptionHandlinginCSharp.aspx" target="_blank">exception</a>.</p>
<p>Here is another example. This will allow access if the user is a Sitecore administrator, and block everyone else:</p>
<pre name="code" class="csharp">
[PrincipalPermission(SecurityAction.Demand, Role=&quot;Administrator&quot;)]
private void WriteText()
{
  // ... your code here
}
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/briancaos.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/briancaos.wordpress.com/271/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/briancaos.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/briancaos.wordpress.com/271/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/briancaos.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/briancaos.wordpress.com/271/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/briancaos.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/briancaos.wordpress.com/271/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/briancaos.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/briancaos.wordpress.com/271/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=271&subd=briancaos&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://briancaos.wordpress.com/2009/04/01/using-declarative-security-in-sitecore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/25db0dbe9728e65c205cb902b4aa9741?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">briancaos</media:title>
		</media:content>

		<media:content url="http://briancaos.files.wordpress.com/2009/04/formsdataviewer.jpg?w=300" medium="image">
			<media:title type="html">Forms Data Viewer</media:title>
		</media:content>
	</item>
		<item>
		<title>decodeURIComponent() equivalent in C#</title>
		<link>http://briancaos.wordpress.com/2009/03/31/decodeuricomponent-equivalent-in-c/</link>
		<comments>http://briancaos.wordpress.com/2009/03/31/decodeuricomponent-equivalent-in-c/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 09:41:51 +0000</pubDate>
		<dc:creator>briancaos</dc:creator>
				<category><![CDATA[General .NET]]></category>
		<category><![CDATA[decodeURIComponent]]></category>
		<category><![CDATA[EscapeDataString]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://briancaos.wordpress.com/?p=262</guid>
		<description><![CDATA[The Javascript decodeURIComponent()  function decodes a string that was URI encoded with the encodeURIComponent() Javascript function. If you wish to encode a string in C# that can be decoded with decodeURIComponent you have to use the EscapeDataString function:

System.Uri.EscapeDataString(&#34;This is my text&#34;);

The escaping an unescaping of strings can for example be used to add HTML strings [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=262&subd=briancaos&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The Javascript <a href="http://www.w3schools.com/jsref/jsref_decodeURIComponent.asp" target="_blank">decodeURIComponent()</a>  function decodes a string that was URI encoded with the <a href="http://www.w3schools.com/jsref/jsref_encodeURIComponent.asp" target="_blank">encodeURIComponent()</a> Javascript function. If you wish to encode a string in C# that can be decoded with decodeURIComponent you have to use the <a href="http://msdn.microsoft.com/en-us/library/system.uri.escapedatastring.aspx" target="_blank">EscapeDataString</a> function:</p>
<pre name="code" class="csharp">
System.Uri.EscapeDataString(&quot;This is my text&quot;);
</pre>
<p>The escaping an unescaping of strings can for example be used to add HTML strings to a Javascript array from C#. Adding HTML strings to an array using the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerarraydeclaration.aspx" target="_blank">ClientScript.RegisterArrayDeclaration()</a> function will produce an error when the page is executed. But if you encode/decode the strings, the function will succeed:</p>
<pre name="code" class="csharp">
protected void Page_Load(object sender, EventArgs e)
{
  StringBuilder sb = new StringBuilder();
  sb.AppendFormat(&quot;\&quot;{0}\&quot;&quot;, Uri.EscapeDataString(&quot;
&lt;h1&gt;This is my first heading&lt;/h1&gt;
&quot;));
  sb.AppendFormat(&quot;\&quot;{0}\&quot;&quot;, Uri.EscapeDataString(&quot;
&lt;h2&gt;This is my second heading&lt;/h2&gt;
&quot;));
  sb.AppendFormat(&quot;\&quot;{0}\&quot;&quot;, Uri.EscapeDataString(&quot;
&lt;h3&gt;This is my third heading&lt;/h3&gt;
&quot;));
  Page.ClientScript.RegisterArrayDeclaration(&quot;myArray&quot;, sb.ToString());
}
</pre>
<p>This function appends 3 HTML strings to an array and adds the array to the page. The strings are now accessible from Javascript. This pseudo function will take an ID of a <a href="http://www.w3schools.com/tags/tag_DIV.asp" target="_blank">DIV tag</a> and the index of the array and output the text from the above created array in the DIV tag:</p>
<pre name="code" class="javascript">
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;
  function ShowDescription(divID, index)
  {
    var divTag = document.getElementById(divID);
    divTag.innerHTML = decodeURIComponent( myArray[index] );
  }
&lt;/script&gt;
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/briancaos.wordpress.com/262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/briancaos.wordpress.com/262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/briancaos.wordpress.com/262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/briancaos.wordpress.com/262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/briancaos.wordpress.com/262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/briancaos.wordpress.com/262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/briancaos.wordpress.com/262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/briancaos.wordpress.com/262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/briancaos.wordpress.com/262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/briancaos.wordpress.com/262/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=262&subd=briancaos&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://briancaos.wordpress.com/2009/03/31/decodeuricomponent-equivalent-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/25db0dbe9728e65c205cb902b4aa9741?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">briancaos</media:title>
		</media:content>
	</item>
		<item>
		<title>Streaming objects into a cookie</title>
		<link>http://briancaos.wordpress.com/2009/03/24/streaming-objects-into-a-cookie/</link>
		<comments>http://briancaos.wordpress.com/2009/03/24/streaming-objects-into-a-cookie/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 12:10:39 +0000</pubDate>
		<dc:creator>briancaos</dc:creator>
				<category><![CDATA[General .NET]]></category>
		<category><![CDATA[Sitecore 4]]></category>
		<category><![CDATA[Sitecore 5]]></category>
		<category><![CDATA[Sitecore 6]]></category>
		<category><![CDATA[base64string]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[serialize]]></category>
		<category><![CDATA[stream]]></category>

		<guid isPermaLink="false">http://briancaos.wordpress.com/?p=258</guid>
		<description><![CDATA[Cookies are text strings that is used within the browser memory. In reality, cookies can store anything, as long as you follow these limitations:

Do not store more than 20 cookies per domain.
Do not store more than 4096 bytes per cookie.

Microsoft states that their browser can store at least 20 cookies per domain and at least 4096 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=258&subd=briancaos&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://www.cookiecentral.com/faq/#1.1" target="_blank">Cookies</a> are text strings that is used within the browser memory. In reality, cookies can store anything, as long as you follow these limitations:</p>
<ul>
<li>Do not store more than 20 cookies per domain.</li>
<li>Do not store more than 4096 bytes per cookie.</li>
</ul>
<p>Microsoft states that their browser can <a href="http://support.microsoft.com/kb/306070" target="_blank">store at least 20 cookies per domain</a> and at least 4096 bytes per cookies,  but the <a href="http://www.webmasterworld.com/forum10/8629.htm" target="_blank">official max size is 4k</a>, so <a href="http://www.thismuchiknow.co.uk/?p=13" target="_blank">you should stick to this</a>.</p>
<p>With this in mind, my proposal to stream objects into a cookie is probably not such a good idea. There is some overhead when streaming classes in C#, as the class definitions are also stored. However, if you observe the limits as described above, you should be fine. The following piece of code saved me a lot of time, that&#8217;s for sure.</p>
<p>The first function will store a made-up class (called MyClass) into a cookie:</p>
<pre name="code" class="csharp">
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Web;

public void Store(MyClass myClass)
{
  HttpCookie cookie = new HttpCookie(&quot;myCookie&quot;)
  {
    // Set the expiry date of the cookie to 15 years
    Expires = DateTime.Now.AddYears(15)
  };
  Stream myStream = new MemoryStream();
  try
  {
    // Create a binary formatter and serialize the
    // myClass into the memorystream
    IFormatter formatter = new BinaryFormatter();
    formatter.Serialize(myStream, myClass);
    // Go to the beginning of the stream and
    // fill a byte array with the contents of the
    // memory stream
    myStream.Seek(0, SeekOrigin.Begin);
    byte[] buffer = new byte[myStream.Length];
    myStream.Read(buffer, 0, (int)myStream.Length);
    // Store the buffer as a base64 string in the cookie
    cookie.Value = Convert.ToBase64String(buffer);
    // Add the cookie to the current http context
    HttpContext.Current.Response.Cookies.Add(cookie);
  }
  finally
  {
    // ... and remember to close the stream
    myStream.Close();
  }
}
</pre>
<p>One thing to remember is that cookies store strings, not binary data. That&#8217;s why I have to convert the stream to a byte array, and convert the byte array to a <a href="http://msdn.microsoft.com/en-us/library/system.convert.tobase64string.aspx" target="_blank">base 64 string</a>. This conversion introduces <a href="http://en.wikipedia.org/wiki/Base64" target="_blank">another overhead</a> as base64 strings converts 3 bytes into 4 ASCII chars.</p>
<p>Now lets restore my object from the cookie:</p>
<pre name="code" class="csharp">
public MyClass Restore()
{
  // Always remember to check that the cookie is not empty
  HttpCookie cookie = HttpContext.Current.Request.Cookies[&quot;myCookie&quot;];
  if (cookie != null)
  {
    // Convert the base64 string into a byte array
    byte[] buffer = Convert.FromBase64String(cookie.Value);
    // Create a memory stream from the byte array
    Stream myStream = new MemoryStream(buffer);
    try
    {
      // Create a binary formatter and deserialize the
      // contents of the memory stream into MyClass
      IFormatter formatter = new BinaryFormatter();
      MyClass streamedClass = (MyClass)formatter.Deserialize(myStream);
      return streamedClass;
    }
    finally
    {
      // ... and as always, close the stream
      myStream.Close();
    }
  }
  return null;
}
</pre>
<p>If you replace the <strong>MyClass</strong> with an <a href="http://msdn.microsoft.com/en-us/library/87d83y5b(VS.80).aspx" target="_blank">interface </a>or a <a href="http://www.java2s.com/Tutorial/CSharp/0140__Class/0440__Base-Class.htm" target="_blank">base class</a>, you will have the flexibility to store any class either implementing the interface or inheriting from the base class.</p>
<p>And if you need help on how to remove cookies, you can read this article on <a href="http://briancaos.wordpress.com/2008/07/22/add-and-remove-cookies/" target="_blank">how to add and remove cookies</a>.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/briancaos.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/briancaos.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/briancaos.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/briancaos.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/briancaos.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/briancaos.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/briancaos.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/briancaos.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/briancaos.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/briancaos.wordpress.com/258/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briancaos.wordpress.com&blog=4258391&post=258&subd=briancaos&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://briancaos.wordpress.com/2009/03/24/streaming-objects-into-a-cookie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/25db0dbe9728e65c205cb902b4aa9741?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">briancaos</media:title>
		</media:content>
	</item>
	</channel>
</rss>