<?xml version="1.0" encoding="UTF-8"?>
<!--Generated by Squarespace Site Server v5.11.81 (http://www.squarespace.com/) on Fri, 01 Jun 2012 12:57:07 GMT--><feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"><title>SharePoint</title><subtitle>SharePoint</subtitle><id>http://www.usingnat.net/sharepoint/</id><link rel="alternate" type="application/xhtml+xml" href="http://www.usingnat.net/sharepoint/"/><link rel="self" type="application/atom+xml" href="http://www.usingnat.net/sharepoint/atom.xml"/><updated>2011-02-25T14:20:10Z</updated><generator uri="http://www.squarespace.com/" version="Squarespace Site Server v5.11.81 (http://www.squarespace.com/)">Squarespace</generator><entry><title>Looking SharePoint Topologies as Patterns (MOSS 2007)</title><category term="Design Patterns"/><category term="MOSS2007"/><category term="Server Configuration"/><category term="SharePoint Topology"/><id>http://www.usingnat.net/sharepoint/2011/2/25/looking-sharepoint-topologies-as-patterns-moss-2007.html</id><link rel="alternate" type="text/html" href="http://www.usingnat.net/sharepoint/2011/2/25/looking-sharepoint-topologies-as-patterns-moss-2007.html"/><author><name>NaT</name></author><published>2011-02-25T14:04:10Z</published><updated>2011-02-25T14:04:10Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>When I first had to deal with SharePoint 2007 server topologies I had to understand the different possible configurations so I can come up with a configuration that takes performance, availability, redundancy and flexibility in to account. So, I thought it would be cool to think of SharePoint server configurations as patterns and anti-patterns and be able to identify them quickly without going into details and be able to communicate it to others.</p>
<p>To start with, let me just define what design patterns in Software engineering are (got it from&nbsp;Wikipedia):</p>
<p style="padding-left: 30px;"><em>Pattern:</em> a design pattern is a general reusable solution to commonly occurring problem in software design.</p>
<p style="padding-left: 30px;"><em>Anti-Pattern:</em> an anti-pattern is a design pattern that may be commonly used but is ineffective and/or counterproductive in practice.</p>
<p><span style="color: #365f91;"><strong><span style="text-decoration: underline;">SharePoint Server Roles</span></strong></span></p>
<p><span style="color: #365f91;">Let me first describe the different server roles in SharePoint 2007. </span></p>
<p><span style="color: #365f91;"><strong style="font-size: 150%; color: red;">Be aware: it's targeted for MOSS 2007 (not SharePoint 2010).<br /></strong></span></p>
<p><span style="color: #365f91;"><strong>WFE&nbsp; <span class="full-image-float-left ssNonEditable"><span><img src="http://www.usingnat.net/storage/WFE.png?__SQUARESPACE_CACHEVERSION=1298642042302" alt="" /></span></span><span class="full-image-block ssNonEditable"><span>&nbsp;</span></span></strong></span></p>
<p>Any server in SharePoint that has the &ldquo;Windows SharePoint Services Web Application&rdquo; service is a Web-Front-End. That means your Web Applications is configured on each one of the web-front-ends and can potentially receiver requests from end-users through IIS Web Sites.</p>
<p>Whether a WFE serves end-users or not matters on which one of the WFEs you load balance and expose it to end user requests. So that means just because a server has the &ldquo;Windows SharePoint Services Web Application&rdquo; service installed, it does not mean it is receiving requests from end-users (very important point).</p>
<p>&nbsp;</p>
<p><span style="color: #365f91;"><strong>QUERY<span class="full-image-float-left ssNonEditable"><span><img src="http://www.usingnat.net/storage/DB.png?__SQUARESPACE_CACHEVERSION=1298642277732" alt="" /></span></span></strong></span></p>
<p>A server with a query role is a search server in SharePoint that has the &ldquo;Office SharePoint Server Search&rdquo; service running and configured for serving search queries.</p>
<p>SharePoint out-of-the-box can load balance the query role for you. That means you can have more than one server with the query role.</p>
<p><span style="color: #365f91;"><strong><span class="full-image-block ssNonEditable"><span style="color: #365f91;"><strong><span class="full-image-float-left ssNonEditable"><span><img src="http://www.usingnat.net/storage/INDEX.png?__SQUARESPACE_CACHEVERSION=1271966856057" alt="" /></span></span></strong></span></span></strong></span><span style="color: #365f91;"><strong>INDEX<span class="full-image-block ssNonEditable"><span style="color: #365f91;">&nbsp;</span></span></strong></span></p>
<p>A server with a query role is a server in SharePoint that has the &ldquo;Office SharePoint Server Search&rdquo; service running and configured for indexing content.</p>
<p>SharePoint by design cannot load balance the index role. That means you can only have one server having the index role, unless you configure another SSP (you can only have one index per SSP).</p>
<p>&nbsp;</p>
<p><span style="color: #365f91;"><strong> <span class="full-image-float-left ssNonEditable"><span><img src="http://www.usingnat.net/storage/EXCEL.png?__SQUARESPACE_CACHEVERSION=1271966755300" alt="" /></span></span></strong></span></p>
<p><span style="color: #365f91;"><strong>EXCEL</strong></span></p>
<p><span style="color: #365f91;"><strong> </strong></span></p>
<p>A server with an excel role is a server in SharePoint that has the &ldquo;Excel Calculation Service&rdquo; running. It is basically used to do excel calculation and render excel content to SharePoint sites. And, this role can be load balanced easily by SharePoint.</p>
<p><strong><span class="full-image-float-left ssNonEditable"><span><img src="http://www.usingnat.net/storage/CA.png?__SQUARESPACE_CACHEVERSION=1271966689586" alt="" /></span></span></strong></p>
<p><strong>CA</strong></p>
<p>A server hosting the Central Administration Web Application</p>
<p>&nbsp;</p>
<p><strong>DB<span class="full-image-float-left ssNonEditable"><span><img src="http://www.usingnat.net/storage/DB.png?__SQUARESPACE_CACHEVERSION=1298642071597" alt="" /></span></span><br /></strong></p>
<p>A database server (or cluster) hosting the content databases, the configuration database and other SharePoint databases.</p>
<p><span style="color: #4f6228;"><strong>&nbsp;</strong></span></p>
<p><span style="color: #4f6228;"><strong>The Standalone Configuration</strong></span></p>
<p>I will start with the standalone configuration, because that&rsquo;s where all the anti-patterns arise. The standalone configuration is basically having all the roles on a single server and we will branch out patterns and anti-patterns from it.</p>
<p>&nbsp;<span class="full-image-block ssNonEditable"><span><img src="http://www.usingnat.net/storage/StandaloneConfig.png?__SQUARESPACE_CACHEVERSION=1298641546908" alt="" /></span></span></p>
<p><strong><span style="font-size: 140%;">The Anti-Patterns</span></strong></p>
<p><span style="color: #943634;"><strong><span style="font-size: 120%;">Propagation Anti-Pattern</span></strong></span></p>
<p>One of the common mistakes when configuring an application server is assigning the same server the Query and Index role. Don&rsquo;t ask me why, but for some reason if the index finds the query role on the same box, the indexer assumes that there is no other server in the farm that has the query role, therefore does not propagate index to other query servers. So, don&rsquo;t forget! Make sure you don&rsquo;t assign the query and index role for the same server and assume other load balanced query servers to be functional.</p>
<p><span style="color: #943634;">&nbsp;<span class="full-image-block ssNonEditable"><span><img src="http://www.usingnat.net/storage/Propa.png?__SQUARESPACE_CACHEVERSION=1298641569232" alt="" /></span></span></span></p>
<p><span style="color: #943634;"><strong><span style="font-size: 120%;">Disk-I/O Anti-Pattern</span></strong></span></p>
<p>Database Operations really depends a lot on the physical storage, and a lot of Disk I/O happens on a database server. Because of that, having the WFE role on the same server will affect the performance of the SharePoint site because the worker process will compete with the database server for resources. And this is actually the first thing you should avoid, as you will improve your SharePoint site performance significantly if you have the database role on a dedicated box.</p>
<p><span class="full-image-block ssNonEditable"><span><img src="http://www.usingnat.net/storage/disk.png?__SQUARESPACE_CACHEVERSION=1298641584683" alt="" /></span></span></p>
<p><span style="color: #943634;"><strong><span style="font-size: 120%;">Exposed-CA Anti-Pattern</span></strong></span></p>
<p>A common mistake you can make, is hosting the central administration Web Application on a Web Front End (a web front end that actually serves requests). Say, the WFE box is compromised, that would expose the central administration for an attack (you wouldn&rsquo;t want that, would you?). You need to take care of one thing though, the central administration web application located on a complicatedly separate box could still be vulnerable, and so you need to plan how to protect the central admin box from the WFEs (be it with some kind of firewall, or whatever).&nbsp;&nbsp;</p>
<p>&nbsp;<span class="full-image-block ssNonEditable"><span><img src="http://www.usingnat.net/storage/Exposed.png?__SQUARESPACE_CACHEVERSION=1298641596581" alt="" /></span></span></p>
<p><span style="font-size: 140%;"><strong>The Patterns</strong></span></p>
<p><span style="color: #4f6228;"><strong><span style="font-size: 120%;">Database-Separation Pattern</span></strong></span></p>
<p>Like I mentions on the Disk-IO anti-pattern, you can easily increase your SharePoint site performance by having a dedicated server. And, that&rsquo;s the first thing you should consider, therefore the Database-separation pattern.</p>
<p><span class="full-image-block ssNonEditable"><span><img src="http://www.usingnat.net/storage/database.png?__SQUARESPACE_CACHEVERSION=1298641613590" alt="" /></span></span></p>
<p><span style="color: #4f6228;"><strong><span style="font-size: 120%;">Request-Separation Pattern</span></strong></span></p>
<p>This pattern separates the Web-Front-End from the Application server. Using this pattern, you solve 2 major issues:</p>
<ul>
<li>By separating the WFE from the CA, you can have a chance to protect the Central Administration Web Application.</li>
<li>The indexing can consume server resources. So, separating the WFE from the indexer will be another performance boost after applying &ldquo;The database separation pattern&rdquo;.</li>
</ul>
<p><span class="full-image-block ssNonEditable"><span><img src="http://www.usingnat.net/storage/Request.png?__SQUARESPACE_CACHEVERSION=1298641630599" alt="" /></span></span></p>
<p><span style="color: #4f6228;"><strong><span style="font-size: 120%;">Query-Separation Pattern</span></strong></span></p>
<p>I mentioned earlier that if the index and query are on the same box, the index will not propagate index on to other query servers. So, by separating the query role into a different server, you avoid the propagation issue and at least you give yourself the flexibility to add more query servers as you need them (note that I have the WFE and the Query role on the same box, if you only have 3 boxes then that&rsquo;s the best way to go, but if you anticipate a lot of query requests it might be a good idea to have a dedicated query server).</p>
<p><span style="color: #4f6228;">&nbsp;<span class="full-image-block ssNonEditable"><span><img src="http://www.usingnat.net/storage/Query.png?__SQUARESPACE_CACHEVERSION=1298641645419" alt="" /></span></span></span></p>
<p><span style="color: #4f6228;"><strong><span style="font-size: 120%;">Target-Box Pattern</span></strong></span></p>
<p>Didn&rsquo;t we talk about &ldquo;The exposed-CA anti-pattern&rdquo; and &ldquo;the competing-Indexer anti pattern&rdquo; earlier? Then, WTF is the WFE role doing with the CA and Index role? The answer is simple: I am not really using the second WFE for end-user requests (the one with the CA and other roles), it&rsquo;s not load balanced or does not get end-user requests at all. I can even hide it behind a firewall. The reason I have it: is to avoid the request load on the end-user WFEs that is coming from the indexer. You basically have a target box for the indexer. Target box pattern also avoids the extra hop on the network, because the calls from the indexer would be local.</p>
<p><span style="color: #4f6228;">&nbsp;<span class="full-image-block ssNonEditable"><span><img src="http://www.usingnat.net/storage/Target.png?__SQUARESPACE_CACHEVERSION=1298641659057" alt="" /></span></span></span></p>
<p><span style="color: #4f6228;"><strong><span style="font-size: 120%;">Request-Load-Balancing Pattern</span></strong></span></p>
<p>You have applied &ldquo;The database separation pattern&rdquo;, &ldquo;The request separation pattern&rdquo;, &ldquo;The query separation pattern&rdquo;, and you have avoided the exposure of the CA, you have increased the performance of the WFE, and you have given the query a chance for load balancing.</p>
<p>So, now it&rsquo;s time to care for your Web-Front-Ends. By adding a second WFE not only you make your SharePoint more available (if one is down, you got the other still running) but you also increase performance by distributing request loads. Note that, your query request is also load balanced, this makes your farm more available (if one query is down, the other will take it).</p>
<p><span style="color: #4f6228;">&nbsp;<span class="full-image-block ssNonEditable"><span><img src="http://www.usingnat.net/storage/RequestLoad.png?__SQUARESPACE_CACHEVERSION=1298641675287" alt="" /></span></span></span></p>
<p><span style="color: #4f6228;"><strong><span style="font-size: 120%;">Available-Database Pattern</span></strong></span></p>
<p>When you first applied &ldquo;The database-separation pattern&rdquo;, you gained a significant performance. Now, you should plan how to make your server available. Pretty simple, you use SQL Server clustering. Take note here, that SharePoint doesn&rsquo;t really know about the database cluster; SharePoint just refers to the database as if it was a single server. And, it&rsquo;s pretty much the job of SQL server to manage the cluster. You pretty much have two options when clustering database servers: Active-Active or Active-Passive clustering. You either have both as active or you can have one active and the other passive where one of the database servers is active and the other stays inactive and waiting for the other to fail and take over, therefore &ldquo;The available-Database pattern&rdquo; (I am not an expert on this subject but you can use the technique of Database Mirroring to make your database redundant).</p>
<p><span class="full-image-block ssNonEditable"><span><img src="http://www.usingnat.net/storage/AvailableDatabase.png?__SQUARESPACE_CACHEVERSION=1298641694395" alt="" /></span></span></p>
<p>&nbsp;</p>
<p><span style="color: #4f6228;"><strong><span style="font-size: 120%;">X5 Pattern</span></strong></span></p>
<p>When you apply &ldquo;The database-separation&rdquo;, &ldquo;The request-separation&rdquo;, &ldquo;The query-separation&rdquo;, &ldquo;The target-box&rdquo;, &ldquo;The available-database&rdquo; and &ldquo;the request-load-balancing&rdquo; patterns, you end up with a minimum of 5 servers forming an X, therefore I call it the X5 pattern. Note that if you&rsquo;re avoiding &ldquo;The propagation anti-pattern&rdquo; and trying to load balancing search then you pretty much end up assigning the query roles to both WFEs.</p>
<p><span style="color: #4f6228;">&nbsp;<span class="full-image-block ssNonEditable"><span><img src="http://www.usingnat.net/storage/X5.png?__SQUARESPACE_CACHEVERSION=1298641711119" alt="" /></span></span></span></p>
<p><span style="color: #4f6228;"><strong><span style="font-size: 120%;">Web-X6 Pattern</span></strong></span></p>
<p>This is pretty much the X5 pattern, with one additional server targeted for Web request. From applying the X-5 pattern we ended up load balancing the query role on both WFEs, and now you might need to plan to have an additional WFE not to over kill the 2 WFEs. That also gives you a chance to just leave the index alone and separate the Excel to the 3<sup>rd</sup> WFE or perhaps load balance the Excel role between the 3<sup>rd</sup> WFE and the application box. With this pattern, you can pretty much load balance WFE, Query and perhaps Excel services.</p>
<p><span class="full-image-block ssNonEditable"><span><img src="http://www.usingnat.net/storage/Web-X6.png?__SQUARESPACE_CACHEVERSION=1298641740677" alt="" /></span></span></p>
<p><span style="color: #4f6228;"><strong><span style="font-size: 120%;">App-X6 Pattern</span></strong></span></p>
<p>The Web-X6 pattern can perhaps fit for a farm where WFEs do a lot of user authentication for collaboration reasons (authentication could be expensive, so therefore an additional WFE would definitely help). On the other hand, The Application-X6 pattern targets the query role. If you are expecting a lot of search queries, then it might be a better idea to have a dedicated query server than having a 3<sup>rd</sup> WFE, for that reason you add a 2<sup>nd</sup> application server and that can primarily be used for query but you can also use it to host a second CA or separate the CA from the index server (btw if you are having the CA with Query server you can perhaps stop IIS, and start it back whenever you need it, that way you don&rsquo;t have to worry about having using up the memory), and you can also use the same box to load balance the Excel Role if Excel services availability is very important.</p>
<p><strong><span style="color: #4f6228;">&nbsp;<span class="full-image-block ssNonEditable"><span><img src="http://www.usingnat.net/storage/App-X6.png?__SQUARESPACE_CACHEVERSION=1298641756800" alt="" /></span></span></span></strong></p>
<p><strong><span style="color: #4f6228;">Conclusion</span></strong></p>
<p>This was more of an excercise to go through the process of identifying and understand the different topologies. Please make sure you research and plan before you configure your farm, and don&rsquo;t take the patterns black-and-white, as you have to come up with your own topology that best fits your budget and your business.</p>
<p>Thanks,</p>
<p><strong>using(NaT)</strong></p>
<p>&nbsp;</p>
<p><strong>&nbsp;</strong></p>]]></content></entry><entry><title>How to programmatically authenticate to UAG protected SharePoint</title><category term="Advanced SharePoint"/><category term="Authentication"/><category term="Client Object Model"/><category term="SharePoint"/><category term="SharePoint Security"/><category term="SharePoint2010"/><category term="UAG"/><id>http://www.usingnat.net/sharepoint/2011/2/23/how-to-programmatically-authenticate-to-uag-protected-sharep.html</id><link rel="alternate" type="text/html" href="http://www.usingnat.net/sharepoint/2011/2/23/how-to-programmatically-authenticate-to-uag-protected-sharep.html"/><author><name>NaT</name></author><published>2011-02-23T15:48:15Z</published><updated>2011-02-23T15:48:15Z</updated><content type="html" xml:lang="en-US"><![CDATA[<!--  p.MsoNormal 	{margin-top:0in; 	margin-right:0in; 	margin-bottom:10.0pt; 	margin-left:0in; 	line-height:115%; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	} p.MsoListParagraph 	{margin-top:0in; 	margin-right:0in; 	margin-bottom:10.0pt; 	margin-left:.5in; 	line-height:115%; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	} p.MsoListParagraphCxSpFirst 	{margin-top:0in; 	margin-right:0in; 	margin-bottom:0in; 	margin-left:.5in; 	margin-bottom:.0001pt; 	line-height:115%; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	} a:link 	{color:blue; 	text-decoration:underline; 	text-underline:single;             } p.MsoListParagraphCxSpMiddle 	{margin-top:0in; 	margin-right:0in; 	margin-bottom:0in; 	margin-left:.5in; 	margin-bottom:.0001pt; 	line-height:115%; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	} p.MsoListParagraphCxSpLast 	{margin-top:0in; 	margin-right:0in; 	margin-bottom:10.0pt; 	margin-left:.5in; 	line-height:115%; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	}          -->
<p class="MsoNormal"><em>this post is not a how-to configure UAG and SharePoint for Authentication. It's about how to programmatically authenticate to UAG and use the SharePoint Client Object Model under the following scenario.</em></p>
<p class="MsoNormal"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">The scenario:</span></p>
<p class="MsoListParagraph" style="text-indent: -.25in; mso-list: l1 level1 lfo1;">&lt;!&nbsp; &nbsp;<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Your SharePoint Site is behind a Forefront Unified Access Gateway (UAG) that&rsquo;s configured to have a single login experience with SSO, by providing you a login page that redirects you to the appropriate ADFS protected SharePoint Content.</span></p>
<p class="MsoListParagraph" style="text-indent: -.25in; mso-list: l1 level1 lfo1;">&nbsp;</p>
<p class="MsoListParagraph" style="text-indent: -.25in; mso-list: l1 level1 lfo1;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><br /></span></p>
<p class="MsoNormal"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">For the SSO to work, UAG has to issue cookie based security token to the user before the SharePoint content can be delivered. When you hit your public SharePoint URL for the first time, UAG responses back with an automatic redirection taking you to a form-based UAG login page. When the user submits their credentials, the cookie-based security token generated by UAG is submitted behind the scene. UAG will then validate the credentials and approves the cookie-based security token. At this point any request to the SharePoint URL with the approved cookie-based security token will be granted access to the SharePoint content.</span></p>
<p class="MsoNormal"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Now, what happens when you connect to the SharePoint URL programmatically?</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">After UAG redirects you to a login Page, it sends you back cookie-based security tokens that you are supposed to submit along with your credentials. If you don&rsquo;t use the cookies, you will be stuck in a loop where UAG will keep redirecting you till you provide a cookie container, and you would reach the maximum automatic redirection allowed by your http request. Therefore you get the following error: &ldquo;Too many automatic redirections were attempted&rdquo; (I talk about this, because that's the first issue I encountered, when dealing witht UAG and SharePoint authentication). </span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">&nbsp;</span></p>
<p class="MsoNormal"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">If you are creating a .NET client application connecting to SharePoint, you would either build proxies against the SharePoint Web Services or use the SharePoint Client Object Model. I choose to use the SharePoint Client Object Model because it&rsquo;s simpler, especially because I don&rsquo;t have to worry about passing canary value (X-Request Digest Information), because that is already taking care of behind the scene.</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">So the first thing you should figure out is how you can pass cookies to each HTTP requests that the SharePoint Client Object Model uses. The answer is simple: Create an event handler to Microsoft.SharePoint.Client.ClientContext ExecutingWebRequest event that initializes a cookie container for the underlying HTTP Request before doing anything. And add the UAG approved cookies to the cookie container.</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">How to get the UAG approved cookies: </span></p>
<p class="MsoListParagraphCxSpFirst" style="margin-bottom: .0001pt; mso-add-space: auto; text-indent: -.25in; line-height: normal; mso-list: l0 level1 lfo2; mso-layout-grid-align: none; text-autospace: none;">&lt;!&nbsp;&nbsp; <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;">1.<span style="font: 7.0pt &amp;amp;amp;">&nbsp;&nbsp;</span></span></span> <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Do a GET on <a href="https://SharePointURL">https://SharePointURL</a></span></p>
<p class="MsoListParagraphCxSpMiddle" style="margin-bottom: .0001pt; mso-add-space: auto; text-indent: -.25in; line-height: normal; mso-list: l0 level1 lfo2; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;">2.<span style="font: 7.0pt &amp;amp;amp;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">2. Get the cookie from the Response</span></p>
<p class="MsoListParagraphCxSpMiddle" style="margin-bottom: .0001pt; mso-add-space: auto; text-indent: -.25in; line-height: normal; mso-list: l0 level1 lfo2; mso-layout-grid-align: none; text-autospace: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">3. Construct the UAG Login Page URL</span></p>
<p class="MsoListParagraphCxSpMiddle" style="margin-bottom: .0001pt; mso-add-space: auto; text-indent: -.25in; line-height: normal; mso-list: l0 level1 lfo2; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4. Do a POST to the UAG Login Page URL with the correct credentials along with the cookie</span></p>
<p class="MsoListParagraphCxSpLast" style="margin-bottom: .0001pt; mso-add-space: auto; text-indent: -.25in; line-height: normal; mso-list: l0 level1 lfo2; mso-layout-grid-align: none; text-autospace: none;">&lt;!&nbsp;&nbsp;<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">5. Then pass the cookie to the ClientContext&rsquo;s underlying HTTP Request using the event handler.</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">I have created a class called CookieAuthenticator that will do the first 4 steps for you and returns the cookies that you can add to the SharePoint client context underlying HTTP request.</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><strong style="mso-bidi-font-weight: normal;"><span style="text-decoration: underline;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">CookieAthenticator:</span></span></strong></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;">&nbsp;</p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> System;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> System.Collections.Generic;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> System.Linq;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> System.Text;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> System.Net;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> System.IO;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">namespace</span><span style="font-size: 8.0pt; font-family: Consolas;"> net.usingnat.SharePoint.Uag</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">CookieAuthenticator</span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af;">NetworkCredential</span> Credential</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">get</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">set</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">string</span> Url</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">get</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">set</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">string</span> UserAgent</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">set</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">get</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">private</span> <span style="color: #2b91af;">CookieCollection</span> Cookies</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">get</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">set</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">private</span> <span style="color: blue;">string</span>[] Queries</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">get</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue;">set</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">private</span> <span style="color: blue;">string</span> ValidationUrl</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">get</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">set</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">private</span> <span style="color: blue;">void</span> Connect()</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af;">HttpWebRequest</span> request = (<span style="color: #2b91af;">HttpWebRequest</span>)<span style="color: #2b91af;">WebRequest</span>.Create(<span style="color: blue;">this</span>.Url);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>request.CookieContainer = <span style="color: blue;">new</span> <span style="color: #2b91af;">CookieContainer</span>();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>request.UserAgent = <span style="color: blue;">this</span>.UserAgent;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">//Do a GET on the SharePoint URL</span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">using</span> (<span style="color: #2b91af;">HttpWebResponse</span> response = (<span style="color: #2b91af;">HttpWebResponse</span>)request.GetResponse())</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">//Get the UAG generated cookies from the response</span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">this</span>.Cookies = response.Cookies;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">//Get the query strings to construct login page URL</span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">this</span>.Queries = response.ResponseUri.Query.Substring(1).Split(<span style="color: blue;">new</span> <span style="color: blue;">string</span>[] { <span style="color: #a31515;">"&amp;"</span> }, <span style="color: #2b91af;">StringSplitOptions</span>.RemoveEmptyEntries);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">this</span>.ValidationUrl = <span style="color: blue;">this</span>.Url;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">//Construct the login page URL</span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">for</span> (<span style="color: blue;">int</span> i = 0; i &lt; response.ResponseUri.Segments.Length - 1; i++)</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">this</span>.ValidationUrl += response.ResponseUri.Segments[i];</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">this</span>.ValidationUrl += <span style="color: #a31515;">"Validate.asp"</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">private</span> <span style="color: blue;">void</span> ValidateCredentials()</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">//Construct the POST HTTP Request Data</span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af;">ASCIIEncoding</span> encoding = <span style="color: blue;">new</span> <span style="color: #2b91af;">ASCIIEncoding</span>();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">string</span> postData = <span style="color: blue;">string</span>.Empty;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>postData += <span style="color: blue;">string</span>.Format(<span style="color: #a31515;">"user_name={0}"</span>, <span style="color: blue;">this</span>.Credential.UserName);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>postData += <span style="color: blue;">string</span>.Format(<span style="color: #a31515;">"&amp;password={0}"</span>, <span style="color: blue;">this</span>.Credential.Password);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>postData += <span style="color: blue;">string</span>.Format(<span style="color: #a31515;">"&amp;repository={0}"</span>, <span style="color: #a31515;">"AD"</span>);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">foreach</span> (<span style="color: blue;">var</span> query <span style="color: blue;">in</span> <span style="color: blue;">this</span>.Queries)</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> (query.Contains(<span style="color: #a31515;">"site_name="</span>)</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>|| query.Contains(<span style="color: #a31515;">"resource_id="</span>)</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>|| query.Contains(<span style="color: #a31515;">"secure="</span>)</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>|| query.Contains(<span style="color: #a31515;">"login_type="</span>))</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>postData += <span style="color: #a31515;">"&amp;"</span> + query;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">byte</span>[] data = encoding.GetBytes(postData);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">//Do a POST on the Login Page URL</span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af;">HttpWebRequest</span> postRequest = (<span style="color: #2b91af;">HttpWebRequest</span>)<span style="color: #2b91af;">WebRequest</span>.Create(<span style="color: blue;">this</span>.ValidationUrl);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>postRequest.ContentType = <span style="color: #a31515;">"application/x-www-form-urlencoded"</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>postRequest.ContentLength = data.Length;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>postRequest.CookieContainer = <span style="color: blue;">new</span> <span style="color: #2b91af;">CookieContainer</span>();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">foreach</span> (<span style="color: #2b91af;">Cookie</span> cookie <span style="color: blue;">in</span> <span style="color: blue;">this</span>.Cookies)</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>postRequest.CookieContainer.Add(cookie);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>postRequest.Method = <span style="color: #a31515;">"POST"</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>postRequest.AllowAutoRedirect = <span style="color: blue;">true</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">using</span> (<span style="color: #2b91af;">Stream</span> newStream = postRequest.GetRequestStream())</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>newStream.Write(data, 0, data.Length);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">//get back the cookies</span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">using</span> (<span style="color: #2b91af;">HttpWebResponse</span> response = (<span style="color: #2b91af;">HttpWebResponse</span>)postRequest.GetResponse())</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">this</span>.Cookies = response.Cookies;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">public</span> CookieAuthenticator(<span style="color: blue;">string</span> url, <span style="color: blue;">string</span> userAgent, <span style="color: #2b91af;">NetworkCredential</span> credentials)</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">this</span>.Url = url;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">this</span>.UserAgent = userAgent;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">this</span>.Credential = credentials;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">public</span> <span style="color: #2b91af;">CookieCollection</span> Authenticate()</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">this</span>.Connect();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">this</span>.ValidateCredentials();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">return</span> <span style="color: blue;">this</span>.Cookies;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 7.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><strong style="mso-bidi-font-weight: normal;"><span style="text-decoration: underline;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Sample Program (How to pass the cookie to the ClientContext):</span></span></strong></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> System;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> System.Collections.Generic;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> System.Linq;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> System.Text;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> System.Web;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> System.IO;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> Microsoft.SharePoint.Client;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> System.ComponentModel;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> System.Data;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">using</span><span style="font-size: 8.0pt; font-family: Consolas;"> System.Net;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas; color: blue;">namespace</span><span style="font-size: 8.0pt; font-family: Consolas;"> net.usingnat.SharePoint.Uag</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">class</span> <span style="color: #2b91af;">Program</span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">private</span> <span style="color: #2b91af;">CookieCollection</span> cookies;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">var</span> program = <span style="color: blue;">new</span> <span style="color: #2b91af;">Program</span>();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>program.Authenticate();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>program.GetData();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">public</span> <span style="color: blue;">void</span> GetData()</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">using</span> (<span style="color: #2b91af;">ClientContext</span> ctx = <span style="color: blue;">new</span> <span style="color: #2b91af;">ClientContext</span>(<span style="color: #a31515;">"https://SharePointURL"</span>))</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ctx.ExecutingWebRequest += <span style="color: blue;">new</span> <span style="color: #2b91af;">EventHandler</span>&lt;<span style="color: #2b91af;">WebRequestEventArgs</span>&gt;(ctx_ExecutingWebRequest);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ctx.AuthenticationMode = <span style="color: #2b91af;">ClientAuthenticationMode</span>.Default;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">var</span> list = ctx.Web.Lists.GetByTitle(<span style="color: #a31515;">"Documents"</span>);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ctx.Load(list);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ctx.ExecuteQuery();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Title: "</span> + list.Title);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Description: "</span> + list.Description);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Count: "</span> + list.ItemCount);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af;">Console</span>.ReadLine();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">public</span> <span style="color: blue;">void</span> Authenticate()</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Enter your username: "</span>);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</span><span style="color: blue;">var</span> userName = <span style="color: #2b91af;">Console</span>.ReadLine();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Enter your password: "</span>);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">var</span> password = <span style="color: #2b91af;">Console</span>.ReadLine();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">var</span> url = <span style="color: #a31515;">"https://SharePointURL"</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">var</span> userAgent = <span style="color: #a31515;">"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">var</span> credentials = <span style="color: blue;">new</span> <span style="color: #2b91af;">NetworkCredential</span>(userName, password);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">var</span> authenticator = <span style="color: blue;">new</span> <span style="color: #2b91af;">CookieAuthenticator</span>(url, userAgent, credentials);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">this</span>.cookies = authenticator.Authenticate();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">private</span> <span style="color: blue;">void</span> ctx_ExecutingWebRequest(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">WebRequestEventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>e.WebRequestExecutor.WebRequest.CookieContainer = <span style="color: blue;">new</span> <span style="color: #2b91af;">CookieContainer</span>();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">foreach</span> (<span style="color: #2b91af;">Cookie</span> cookie <span style="color: blue;">in</span> <span style="color: blue;">this</span>.cookies)</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>e.WebRequestExecutor.WebRequest.CookieContainer.Add(cookie);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 8.0pt; font-family: Consolas;">}</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">The next step should be how to sign-out from UAG. Well, if you figure that out please let me know.</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Thanks,</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Using NaT</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">&nbsp;</span></p>
<p class="MsoNormal"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">&nbsp;</span></p>]]></content></entry><entry><title>Add-SPSolution : "Access Denied" Vicious Circle (SharePoint 2010)</title><category term="Add-SPShellAdmin"/><category term="Add-SPSolution"/><category term="Get-SPShellAdmin"/><category term="PowerShell"/><category term="SharePoint2010"/><category term="SharePoint2010"/><id>http://www.usingnat.net/sharepoint/2010/6/2/add-spsolution-access-denied-vicious-circle-sharepoint-2010.html</id><link rel="alternate" type="text/html" href="http://www.usingnat.net/sharepoint/2010/6/2/add-spsolution-access-denied-vicious-circle-sharepoint-2010.html"/><author><name>NaT</name></author><published>2010-06-02T14:37:53Z</published><updated>2010-06-02T14:37:53Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>If you get an <strong><span style="font-size: 140%;">"Access Denied"</span></strong> when trying to deploy a SharePoint solution using <span style="font-size: 140%;"><strong>PowerShell</strong> </span>in <strong>SharePoint 2010</strong>, then you probably did not run PowerShell as "Run as Administrator" or/and you are not a&nbsp;ShellAdmin.</p>
<p>So, just right-click PowerShell and click <span style="font-size: 130%;"><strong>"Run as Administrator".</strong> </span>If that does not work you&nbsp;then just run <span style="font-size: 120%;"><strong>Get-SPShellAdmin</strong> </span>and see if your account you are using is listed as a ShellAdmin. Initially, only the "Farm&nbsp;Admin" service account&nbsp;is a ShellAdmin (not the "Setup Admin" service account).&nbsp;If your account is listed, then I am sorry I wouldn't know what to say. But, if not then use the <span style="font-size: 120%;"><strong>Add-SPhellAdmin</strong> </span>to add your account. You might run here into a <span style="font-size: 110%;"><strong><span style="font-size: 110%;"><em>vicious circle</em> </span></strong></span>where you would still get "Access Denied" when running <span style="font-size: 120%;">Add-SPShellAdmin</span>. In this case&nbsp;just login as the "Farm Admin" service account and then&nbsp;add your initial account as a Shell Admin.</p>
<p>At this point, you can login back with your initial account, "Run As Administrator", and then run <strong><span style="font-size: 140%;">Add-SPSolution,</span></strong> and hopefully it works for you (finger crossed).</p>
<p>using (NaT)</p>
<p>&nbsp;</p>]]></content></entry><entry><title>Audio file support in a SharePoint Document Library</title><category term="Advanced SharePoint"/><category term="SharePoint; Edit Control Block; Audio files"/><id>http://www.usingnat.net/sharepoint/2009/9/15/audio-file-support-in-a-sharepoint-document-library.html</id><link rel="alternate" type="text/html" href="http://www.usingnat.net/sharepoint/2009/9/15/audio-file-support-in-a-sharepoint-document-library.html"/><author><name>NaT</name></author><published>2009-09-15T20:08:22Z</published><updated>2009-09-15T20:08:22Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>Add an audio file into a SharePoint document library  and try to open it. You will get the following message if you are using  IE 8 (or previous version of IE):</p>
<p><span class="ssNonEditable full-image-block"><span><img src="../../storage/post-images/AUDIO_DOWNLOAD_SHOT.png?__SQUARESPACE_CACHEVERSION=1253045485748" alt="" /></span></span>&nbsp;</p>
<p>If you upload audio files to a regular document  library, SharePoint will sends back the file request as MIME Type of  &ldquo;text/html&rdquo; (maybe text/plain) instead of &ldquo;audio/wav&rdquo; (or something  similar audio type). For that reason, IE is not smart enough to detect  the content is in fact an audio file to launch the appropriate  application, perhaps Windows Media player (Google Chrome can actually  detect it and play the audio file in-browser).</p>
<p><em>The solutions</em> I can think of are the following:</p>
<p><strong>Solution-1:</strong> Change your document library view  to &ldquo;Explorer View&rdquo;, and it will basically detect any file type in your  document library as if they were in your local machine. Keep note that  it is actually running system commands and that might be unsafe.</p>
<p><strong><span class="ssNonEditable full-image-block"><span><span class="ssNonEditable full-image-block"><span><img src="../../storage/post-images/ExplorerView.jpg?__SQUARESPACE_CACHEVERSION=1253045601075" alt="" /></span></span></span></span>Solution-2:</strong> Create an HttpModule to intercept requests to the SharePoint Web  application, detect if an audio file has been request, then respond back  with a MIME type &ldquo;audio/wav&rdquo; instead of &ldquo;text/html&rdquo;, and then let the  browser detect the audio file and open its appropriate windows  application.</p>
<p><strong>Solution-3:</strong> Create a custom Field Type that  uses a form-rendering control that figures out the URL of the audio and  embeds a windows media player to play the audio when item is in &ldquo;View  Properties&rdquo; mode. Then, make use of your new custom field type in your  SharePoint document library.</p>
<p><strong>Solution-4:</strong> Dynamically add &ldquo;Play&rdquo; Edit  Control Block for audio items, and when clicked it navigates to a  SharePoint application page that plays the audio in-browser Windows  Media Player.</p>
<p>Solution-1 is slick and quick way of solving it, if  users are willing to run system commands of course. Solution-2 is  theoretically feasible. Effects are at the web application level, which  makes it interesting, and worth looking at, as you can apply the same  concept to other non-supported files in SharePoint Document libraries.  Solution-3 sounds possible too. In fact I first started out this road,  and realized it will need more effort and time than I expected it would  (If possible I might give it a shot sometime, at least to explore the  intrinsic involved in custom field types, RenderPattern elements and  form-rendering controls). But, if you like the idea of having a &ldquo;Play&rdquo;  ECB specifically added for audio files and let&rsquo;s you play audios from  your browser without opening other apps in your machine, then solution-4  is what you are looking for.</p>
<p>Here you find sample codes. Sample codes!!!! In other words, you have to clean it up on your own.</p>
<p>But anyways, the followings are the <em><span style="text-decoration: underline;">different components of solution-4</span></em>:</p>
<ul>
<li>
<div align="justify"><strong>Audio Library</strong>: A SharePoint document library containing audio files (ex: files with extension .wav)</div>
</li>
<li>
<div align="justify"><strong>Audio-Check Service</strong>: a SharePoint  application Page used as a simple web service that can determine whether  an item in SharePoint is an audio file or not. All it does is receive a  SharePoint item URL, uses the Object Model to determine the extension  of the file, then responses back a Boolean value in an XML format.</div>
</li>
<li>
<div align="justify"><strong>Content Editor Web Part</strong>: added on the same  page as the List View Web Part of the audio library. It will contain  JavaScript codes that uses SharePoint JavaScript Context object and XHR  object to make Ajax calls to Audio-Check Service, determines whether or  not a document is an audio file, and depending on the result decides to  put the &ldquo;Play&rdquo; edit control block for only audio files.</div>
</li>
<li>
<div align="justify"><strong>Audio Player Page</strong>: a SharePoint application page that receives an audio file URL and plays audio on a page using embedded Windows Media Player.</div>
</li>
</ul>
<p><strong><span style="text-decoration: underline;">Audio-Check Service</span></strong></p>
<div align="justify">
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: 1px solid silver; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060;">   1:</span> <span style="color: #0000ff;">using</span> System;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060;">   2:</span> <span style="color: #0000ff;">using</span> System.Collections.Generic;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060;">   3:</span> <span style="color: #0000ff;">using</span> System.Linq;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060;">   4:</span> <span style="color: #0000ff;">using</span> System.Text;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060;">   5:</span> <span style="color: #0000ff;">using</span> System.Web;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060;">   6:</span> <span style="color: #0000ff;">using</span> Microsoft.SharePoint.WebControls;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060;">   7:</span> <span style="color: #0000ff;">using</span> Microsoft.SharePoint;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060;">   8:</span> <span style="color: #0000ff;">namespace</span> NaT.SharePoint.EditControlBlockAudioSupport.WebControls</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060;">   9:</span> {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum10" style="color: #606060;">  10:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> AudioCheckService : LayoutsPageBase</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum11" style="color: #606060;">  11:</span>     {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum12" style="color: #606060;">  12:</span>         <span style="color: #0000ff;">protected</span> WindowsMediaPlayer _mediaPlayer;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum13" style="color: #606060;">  13:</span>         <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnLoad(EventArgs e)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum14" style="color: #606060;">  14:</span>         {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum15" style="color: #606060;">  15:</span>             <span style="color: #0000ff;">base</span>.OnLoad(e);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum16" style="color: #606060;">  16:</span>&nbsp; </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum17" style="color: #606060;">  17:</span>             <span style="color: #0000ff;">string</span> itemId = <span style="color: #0000ff;">this</span>.Request.QueryString[<span style="color: #006080;">"ItemID"</span>];</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum18" style="color: #606060;">  18:</span>             <span style="color: #0000ff;">string</span> listId = <span style="color: #0000ff;">this</span>.Request.QueryString[<span style="color: #006080;">"ListID"</span>];</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum19" style="color: #606060;">  19:</span>             <span style="color: #0000ff;">string</span> audioCheck = <span style="color: #0000ff;">this</span>.Request.QueryString[<span style="color: #006080;">"AudioCheck"</span>];</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum20" style="color: #606060;">  20:</span>&nbsp; </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum21" style="color: #606060;">  21:</span>             </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum22" style="color: #606060;">  22:</span>             <span style="color: #0000ff;">if</span>(audioCheck != <span style="color: #0000ff;">null</span>)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum23" style="color: #606060;">  23:</span>             {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum24" style="color: #606060;">  24:</span>                 SPList list = <span style="color: #0000ff;">this</span>.Web.Lists[<span style="color: #0000ff;">new</span> Guid(listId.Trim())];</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum25" style="color: #606060;">  25:</span>                 SPListItem item = list.GetItemById(Int32.Parse(itemId.Trim()));</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum26" style="color: #606060;">  26:</span>                 <span style="color: #0000ff;">bool</span> displayEditControlBlock = <span style="color: #0000ff;">this</span>.IsItemAnAudioFile(item);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum27" style="color: #606060;">  27:</span>                 <span style="color: #0000ff;">this</span>.ResponseDecision(displayEditControlBlock);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum28" style="color: #606060;">  28:</span>             }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum29" style="color: #606060;">  29:</span>         }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum30" style="color: #606060;">  30:</span>&nbsp; </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum31" style="color: #606060;">  31:</span>         <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">bool</span> IsItemAnAudioFile(SPListItem item)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum32" style="color: #606060;">  32:</span>         {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum33" style="color: #606060;">  33:</span>             <span style="color: #0000ff;">return</span> item.File != <span style="color: #0000ff;">null</span> &amp;&amp; item.File.Name.EndsWith(<span style="color: #006080;">".wav"</span>);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum34" style="color: #606060;">  34:</span>         }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum35" style="color: #606060;">  35:</span>&nbsp; </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum36" style="color: #606060;">  36:</span>         <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> ResponseDecision(<span style="color: #0000ff;">bool</span> decision)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum37" style="color: #606060;">  37:</span>         {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum38" style="color: #606060;">  38:</span>             <span style="color: #0000ff;">this</span>.Response.ClearHeaders();</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum39" style="color: #606060;">  39:</span>             <span style="color: #0000ff;">this</span>.Response.ClearContent();</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum40" style="color: #606060;">  40:</span>             <span style="color: #0000ff;">this</span>.Response.Cache.SetCacheability(HttpCacheability.NoCache);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum41" style="color: #606060;">  41:</span>             <span style="color: #0000ff;">this</span>.Response.AddHeader(<span style="color: #006080;">"Content-type"</span>, <span style="color: #006080;">"text/xml"</span>);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum42" style="color: #606060;">  42:</span>             <span style="color: #0000ff;">this</span>.Response.Write(<span style="color: #006080;">@"&lt;?xml version="</span><span style="color: #006080;">"1.0"</span><span style="color: #006080;">" encoding="</span><span style="color: #006080;">"UTF-8"</span><span style="color: #006080;">" ?&gt;"</span>);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum43" style="color: #606060;">  43:</span>             <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">string</span> cmdPattern = <span style="color: #006080;">@"&lt;Command&gt;{0}&lt;/Command&gt;"</span>;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum44" style="color: #606060;">  44:</span>             <span style="color: #0000ff;">this</span>.Response.Write(<span style="color: #0000ff;">string</span>.Format(cmdPattern, decision.ToString().ToLower()));</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum45" style="color: #606060;">  45:</span>             <span style="color: #0000ff;">this</span>.Response.End();</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum46" style="color: #606060;">  46:</span>         }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum47" style="color: #606060;">  47:</span>     }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum48" style="color: #606060;">  48:</span>     </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum49" style="color: #606060;">  49:</span> }</pre>
</div>
</div>
</div>
<p>&nbsp;</p>
<p><strong><span style="text-decoration: underline;">Audio Player Page</span></strong></p>
<p>For playing back audio you can use &lt;OBJECT /&gt;  HTML Tag for embedding Windows Media Player in your browser, it let&rsquo;s  you pass a URL as a parameter and streams it back for you.</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: 1px solid silver; padding: 4px;">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">&lt;OBJECT <br />  id=<span style="color: #006080;">"{0}"</span> <br />  CLASSID=<span style="color: #006080;">"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"</span> <br />  type=<span style="color: #006080;">"application/x-oleobject"</span> height=<span style="color: #006080;">"500px"</span> width=<span style="color: #006080;">"500px"</span>&gt;<br />  &lt;PARAM NAME=<span style="color: #006080;">"URL"</span> VALUE=<span style="color: #006080;">""</span> /&gt;<br />  &lt;PARAM NAME=<span style="color: #006080;">"SendPlayStateChangeEvents"</span> VALUE=<span style="color: #006080;">"True"</span> /&gt;<br />  &lt;PARAM NAME=<span style="color: #006080;">"AutoStart"</span> VALUE=<span style="color: #006080;">"true"</span> /&gt;<br />  &lt;PARAM NAME=<span style="color: #006080;">"AnimationAtStart"</span> VALUE=<span style="color: #006080;">"true"</span> /&gt;<br />  &lt;PARAM NAME=<span style="color: #006080;">"ShowControls"</span> VALUE=<span style="color: #006080;">"true"</span> /&gt;<br />  &lt;PARAM NAME=<span style="color: #006080;">"ShowAudioControls"</span> VALUE=<span style="color: #006080;">"true"</span> /&gt;<br />  &lt;PARAM NAME=<span style="color: #006080;">"ShowTracker"</span> VALUE=<span style="color: #006080;">"true"</span> /&gt;<br />  &lt;PARAM NAME=<span style="color: #006080;">"EnableTracker"</span> VALUE=<span style="color: #006080;">"true"</span> /&gt;<br />  &lt;PARAM NAME=<span style="color: #006080;">"ShowStatusBar"</span> VALUE=<span style="color: #006080;">"true"</span> /&gt;<br />  &lt;PARAM NAME=<span style="color: #006080;">"ShowDisplay"</span> VALUE=<span style="color: #006080;">"true"</span> /&gt;<br />  &lt;PARAM NAME=<span style="color: #006080;">"AudioStream"</span> VALUE=<span style="color: #006080;">"true"</span> /&gt;<br />  &lt;PARAM NAME=<span style="color: #006080;">"ShowPositionControls"</span> VALUE=<span style="color: #006080;">"true"</span> /&gt;<br />  &lt;PARAM NAME=<span style="color: #006080;">"EnableFullScreenControls"</span> VALUE=<span style="color: #006080;">"true"</span> /&gt;<br />  &lt;PARAM name=<span style="color: #006080;">"uiMode"</span> <span style="color: #0000ff;">value</span>=<span style="color: #006080;">"none"</span> /&gt;<br />   &lt;PARAM name=<span style="color: #006080;">"PlayCount"</span> <span style="color: #0000ff;">value</span>=<span style="color: #006080;">"1"</span> /&gt;<br />   &lt;PARAM name=<span style="color: #006080;">"FileName"</span> <span style="color: #0000ff;">value</span>=<span style="color: #006080;">"{1}"</span> /&gt;<br />&lt;/OBJECT&gt;<br /></pre>
</div>
<p>Create a Web Control that uses the &lt;OBJECT /&gt;  Tag. I would prefer putting the Object Tag format in a different  embedded file have that loaded in your Window Media Player Web Control:</p>
<div align="justify">
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: 1px solid silver; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060;">   1:</span> <span style="color: #0000ff;">using</span> System;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060;">   2:</span> <span style="color: #0000ff;">using</span> System.Collections.Generic;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060;">   3:</span> <span style="color: #0000ff;">using</span> System.Linq;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060;">   4:</span> <span style="color: #0000ff;">using</span> System.Text;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060;">   5:</span> <span style="color: #0000ff;">using</span> System.Web;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060;">   6:</span> <span style="color: #0000ff;">using</span> System.Web.UI;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060;">   7:</span> <span style="color: #0000ff;">using</span> System.Web.UI.WebControls;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060;">   8:</span>&nbsp; </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060;">   9:</span> <span style="color: #0000ff;">namespace</span> NaT.SharePoint.EditControlBlockAudioSupport.WebControls</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum10" style="color: #606060;">  10:</span> {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum11" style="color: #606060;">  11:</span>     </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum12" style="color: #606060;">  12:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> WindowsMediaPlayer : WebControl, INamingContainer</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum13" style="color: #606060;">  13:</span>     {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum14" style="color: #606060;">  14:</span>         <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> FileName{ get; set;}</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum15" style="color: #606060;">  15:</span>         <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> Render(HtmlTextWriter writer)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum16" style="color: #606060;">  16:</span>         {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum17" style="color: #606060;">  17:</span>             <span style="color: #0000ff;">base</span>.Render(writer);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum18" style="color: #606060;">  18:</span>             var template = <span style="color: #0000ff;">this</span>.GetResourceFileAsString(<span style="color: #006080;">"NaT.SharePoint.EditControlBlockAudioSupport.Properties.MediaPlayerObject.xml"</span>);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum19" style="color: #606060;">  19:</span>             var outputMarkup = <span style="color: #0000ff;">string</span>.Format(template, <span style="color: #006080;">"MediaPlayer_"</span> + Guid.NewGuid().ToString(), FileName);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum20" style="color: #606060;">  20:</span>             writer.Write(outputMarkup);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum21" style="color: #606060;">  21:</span>         }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum22" style="color: #606060;">  22:</span>         <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">string</span> GetResourceFileAsString(<span style="color: #0000ff;">string</span> fileName)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum23" style="color: #606060;">  23:</span>         {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum24" style="color: #606060;">  24:</span>             var assembly = Assembly.GetExecutingAssembly();</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum25" style="color: #606060;">  25:</span>             var stream = assembly.GetManifestResourceStream(fileName);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum26" style="color: #606060;">  26:</span>             <span style="color: #0000ff;">if</span> (stream != <span style="color: #0000ff;">null</span>)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum27" style="color: #606060;">  27:</span>             {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum28" style="color: #606060;">  28:</span>                 var streamReader = <span style="color: #0000ff;">new</span> StreamReader(stream);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum29" style="color: #606060;">  29:</span>                 var myText = streamReader.ReadToEnd();</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum30" style="color: #606060;">  30:</span>                 <span style="color: #0000ff;">if</span> (myText != <span style="color: #0000ff;">null</span>) <span style="color: #0000ff;">return</span> myText;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum31" style="color: #606060;">  31:</span>             }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum32" style="color: #606060;">  32:</span>             <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">string</span>.Empty;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum33" style="color: #606060;">  33:</span>         }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum34" style="color: #606060;">  34:</span>     }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum35" style="color: #606060;">  35:</span> }</pre>
</div>
</div>
</div>
<p>Then, basically use the above WindowsMediaPlayer Web Control in your Media Player SharePoint application page.</p>
<p>&nbsp;</p>
<p><strong><span style="text-decoration: underline;">Content Editor Web Part &ndash; JavaScript</span></strong></p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: 1px solid silver; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060;">   1:</span> &lt;script language=<span style="color: #006080;">"javascript"</span>&gt;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060;">   2:</span> function IsAudioFile(m, ctx, itemId)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060;">   3:</span> { </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060;">   4:</span>    var request;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060;">   5:</span>    var url = ctx.HttpRoot + </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060;">   6:</span>     <span style="color: #006080;">"/_layouts/NaT.SharePoint.EditControlBlockHandler/AudioCheckService.aspx?ListID="</span> + </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060;">   7:</span>     ctx.listName + <span style="color: #006080;">"&amp;ItemID="</span> + itemId+ <span style="color: #006080;">"&amp;AudioCheck=true"</span>;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060;">   8:</span>    </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060;">   9:</span>    <span style="color: #0000ff;">if</span> ( window.XMLHttpRequest )</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum10" style="color: #606060;">  10:</span>    {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum11" style="color: #606060;">  11:</span>       request = <span style="color: #0000ff;">new</span> XMLHttpRequest();</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum12" style="color: #606060;">  12:</span>       request.open(<span style="color: #006080;">"GET"</span>, url, <span style="color: #0000ff;">false</span>);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum13" style="color: #606060;">  13:</span>       request.send(<span style="color: #0000ff;">null</span>);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum14" style="color: #606060;">  14:</span>    }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum15" style="color: #606060;">  15:</span>    <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> ( window.ActiveXObject )</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum16" style="color: #606060;">  16:</span>    {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum17" style="color: #606060;">  17:</span>       request = <span style="color: #0000ff;">new</span> ActiveXObject(<span style="color: #006080;">"Microsoft.XMLHTTP"</span>);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum18" style="color: #606060;">  18:</span>       <span style="color: #0000ff;">if</span> ( request )</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum19" style="color: #606060;">  19:</span>       {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum20" style="color: #606060;">  20:</span>          request.open(<span style="color: #006080;">"GET"</span>, url, <span style="color: #0000ff;">false</span>);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum21" style="color: #606060;">  21:</span>          request.send(); </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum22" style="color: #606060;">  22:</span>       }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum23" style="color: #606060;">  23:</span>    }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum24" style="color: #606060;">  24:</span>    <span style="color: #0000ff;">if</span> ( request )</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum25" style="color: #606060;">  25:</span>    {   </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum26" style="color: #606060;">  26:</span>       var commands = request.responseXML.getElementsByTagName(<span style="color: #006080;">"Command"</span>);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum27" style="color: #606060;">  27:</span>       var cmdName = commands[0].firstChild.nodeValue;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum28" style="color: #606060;">  28:</span>       <span style="color: #0000ff;">if</span>(cmdName == <span style="color: #006080;">"true"</span>) <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span>;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum29" style="color: #606060;">  29:</span>       <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span>;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum30" style="color: #606060;">  30:</span>    }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum31" style="color: #606060;">  31:</span> }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum32" style="color: #606060;">  32:</span>&nbsp; </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum33" style="color: #606060;">  33:</span>&nbsp; </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum34" style="color: #606060;">  34:</span> function Custom_AddDocLibMenuItems(m, ctx)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum35" style="color: #606060;">  35:</span> {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum36" style="color: #606060;">  36:</span>     <span style="color: #0000ff;">if</span>(IsAudioFile(m,ctx, currentItemID) == <span style="color: #0000ff;">false</span>) <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span>;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum37" style="color: #606060;">  37:</span>     strAction=<span style="color: #006080;">"window.navigate(ctx.HttpRoot+</span>;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum38" style="color: #606060;">  38:</span>     '/_layouts/NaT.SharePoint.EditControlBlockHandler/AudioCheckService.aspx?ItemFileUrl='+</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum39" style="color: #606060;">  39:</span>     ctx.HttpRoot+currentItemFileUrl)"</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum40" style="color: #606060;">  40:</span>&nbsp; </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum41" style="color: #606060;">  41:</span>     CAMOpt(m,<span style="color: #006080;">"Play"</span>,strAction,<span style="color: #006080;">""</span>);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum42" style="color: #606060;">  42:</span>     CAMSep(m);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum43" style="color: #606060;">  43:</span>&nbsp; </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum44" style="color: #606060;">  44:</span>     <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span>;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum45" style="color: #606060;">  45:</span> }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum46" style="color: #606060;">  46:</span>&nbsp; </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum47" style="color: #606060;">  47:</span>&nbsp; </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum48" style="color: #606060;">  48:</span> &lt;/script&gt;</pre>
</div>
</div>
<p>&nbsp;</p>
<p>Your final out come should be something like this:</p>
<p><strong><span style="text-decoration: underline;">Play ECB</span></strong></p>
<p><span class="ssNonEditable full-image-block"><span><img src="../../storage/post-images/Play_ECB.jpg?__SQUARESPACE_CACHEVERSION=1253045635711" alt="" /></span></span>&nbsp;</p>
<p>And, after clicking &ldquo;Play&rdquo;, you will be navigated to the media player application page.</p>
<p><span class="ssNonEditable full-image-block"><span><img src="../../storage/post-images/Audio_Player.jpg?__SQUARESPACE_CACHEVERSION=1253045671573" alt="" /></span></span>&nbsp;</p>
<p>Happy coding,</p>
<p><a href="../../" target="_blank">NaT</a></p>]]></content></entry><entry><title>SharePoint People Picker: Override Validation Logic</title><category term="Advanced SharePoint"/><category term="Override Validation"/><category term="People Editor"/><category term="People Picker"/><category term="SharePoint"/><id>http://www.usingnat.net/sharepoint/2009/6/2/sharepoint-people-picker-override-validation-logic.html</id><link rel="alternate" type="text/html" href="http://www.usingnat.net/sharepoint/2009/6/2/sharepoint-people-picker-override-validation-logic.html"/><author><name>NaT</name></author><published>2009-06-02T20:51:02Z</published><updated>2009-06-02T20:51:02Z</updated><summary type="html" xml:lang="en-US"><![CDATA[<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes">using</span><span style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"> SharePointControls = Microsoft.SharePoint.WebControls;</span></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none">&nbsp;</p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes">namespace</span><span style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"> NaT.SharePoint.WebControls</span></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes">{</span></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"><span style="COLOR: blue">public</span> <span style="COLOR: blue">class</span> <span style="COLOR: #2b91af">PeopleEditor</span> : SharePointControls.<span style="COLOR: #2b91af">PeopleEditor</span></span></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes">{</span></p>
<p style="LINE-HEIGHT: normal; TEXT-INDENT: 0.5in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes">//...........</span></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes">}</span></p>
<p style="MARGIN: 0in 0in 10pt"><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes">}</span></p>]]></summary></entry><entry><title>Cross-Application Membership Access Provider Model</title><category term="Advanced SharePoint"/><category term="Cross Application Membership Provider"/><category term="Form-based Authentication"/><category term="Membership Providers"/><id>http://www.usingnat.net/sharepoint/2009/2/24/cross-application-membership-access-provider-model.html</id><link rel="alternate" type="text/html" href="http://www.usingnat.net/sharepoint/2009/2/24/cross-application-membership-access-provider-model.html"/><author><name>NaT</name></author><published>2009-02-24T04:49:00Z</published><updated>2009-02-24T04:49:00Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">A while ago I came to a need to instantiate membership providers dispersed across a SharePoint farm where each membership provider is configured to work with separate web application, and recently I stripped the idea out to a component that you can easily reuse for different applications, therefore, Cross Application Membership Access Provider Model (The CAMAP Model, pronounced k-map), as the name depicts, it&rsquo;s a model you can use to access membership providers across a farm. I will start brushing about Form-based authentication and membership providers in SharePoint as the CAMAP model relates to that, then I will explain the problem matter that lead me to design the model. </span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">A SharePoint web application can use different kind of authentication mechanism (Windows, Forms and Web single sign on) each realized on their own separate zone and separate IIS web site. Membership providers comes in play when the authentication mechanism is of type Forms. FBA (form-Based authentication) is a widely used authentication mechanism for internet facing ASP.NET applications. As SharePoint is built on top of ASP.NET 2.0 it uses FBA to authenticate membership users. The ASP.NET authentication provider model enables SharePoint to store user membership data in different kind of repository (such as SQL Server, AD LDS or any other LDAP compliant store including AD) and authenticates users using the Microsoft Membership Provider interface that all membership providers should adhere to. Membership providers simply provide an interface between SharePoint and a membership user repository. </span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">Under a typical requirement involving membership users, you would be required to refer to the current membership provider (MP) from your ASP.NET context, where that particular MP is configured with a particular zone (internet, intranet, or extranet zone be it) of your current web application. So in your ASP.NET context (which can be a Web Part context), you would get a reference of the default membership provider like this:</span></p>
<p align="left"><span style="FONT-FAMILY: verdana, geneva"><span style="FONT-SIZE: medium"><span style="FONT-SIZE: small"><span style="LINE-HEIGHT: 115%">System.Web.Security.<span style="COLOR: #2b91af">MembershipProvider</span> provider = System.Web.Security.<span style="COLOR: #2b91af">Membership</span>.Provider;</span></span><span style="LINE-HEIGHT: 115%"> </span></span></span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">And, if the provider is not the default one you get to it like this:</span></p>
<p align="left"><span style="FONT-SIZE: small"><span style="FONT-FAMILY: verdana, geneva">System.Web.Security.<span style="COLOR: #2b91af">MembershipProvider</span> provider =</span></span></p>
<p align="left"><span style="FONT-FAMILY: verdana, geneva"><span style="FONT-SIZE: medium"><span style="LINE-HEIGHT: 115%"><span style="FONT-SIZE: small">System.Web.Security.<span style="COLOR: #2b91af">Membership</span>.Providers[<span style="COLOR: #a31515">"providername"</span>];</span></span></span></span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">System.Web.Security.Membership class only holds references to providers that are already defined in the current application configuration file, but if for some reason the provider definition is dynamic or is from an external source, you can programmatically instantiate a provider object, by passing your provider settings to a factory method of ProvidersHelper class. </span></p>
<p align="left"><span style="FONT-SIZE: small"><span style="FONT-FAMILY: verdana, geneva"><span style="LINE-HEIGHT: 115%; COLOR: #2b91af">ProviderSettings</span><span style="LINE-HEIGHT: 115%"> ps = <span style="COLOR: blue">new</span> <span style="COLOR: #2b91af">ProviderSettings</span>();</span></span></span></p>
<p align="left"><span style="FONT-SIZE: small"><span style="FONT-FAMILY: verdana, geneva"><span style="LINE-HEIGHT: 115%">ps.Parameters.Add(&ldquo;attribute name&rdquo;, &ldquo;attribute value&rdquo;);</span></span></span></p>
<p align="left"><span style="FONT-SIZE: small"><span style="FONT-FAMILY: verdana, geneva">System.Web.Security.<span style="COLOR: #2b91af">MembershipProvider</span> p = (System.Web.Security.<span style="COLOR: #2b91af">MembershipProvider</span>)</span></span></p>
<p align="left"><span style="FONT-SIZE: small"><span style="FONT-FAMILY: verdana, geneva">System.Web.Configuration.<span style="COLOR: #2b91af">ProvidersHelper</span>.InstantiateProvider(ps, <span style="COLOR: blue">typeof</span>(System.Web.Security.<span style="COLOR: #2b91af">MembershipProvider</span>));</span></span></p>
<p align="left"><span style="FONT-FAMILY: verdana, geneva"><span style="FONT-SIZE: medium"><br /></span></span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">You can possibly get to another Web Application configuration file, read provider definition, and using ProviderSettings and ProvidersHelper class to instantiate a provider and use it. That&rsquo;s pretty much the idea behind how to use providers dispersed across a SharePoint farm, but, if your membership provider is using a connection string, you might be stack. From <a href="http://msdn.microsoft.com/en-us/library/ms972319.aspx" target="_blank">Provider Model Design Pattern and Specification</a>, it states: &ldquo;All providers that require a connection to a database or require the use of a connection string to locate their data store should use the &lt;connectionStrings/&gt; section of configuration. Additionally, the name of the property on the provider should beconnectionStringNamewith the value being the named value in &lt;connectionStrings/&gt;... An exception will be thrown when a provider attempts to use a connection string obtained from &lt;connectionStrings/&gt; that either does not exist or is invalid.&rdquo;</span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">Unfortunately, It is not possible to pass a connection string to <em>ProvidersHelper</em>; the instantiated provider will try to find its connection string by name, from the application configuration file. Even if I can programmatically set other provider settings, I have to have connection string information in my application configuration file. </span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">Programs running in a .NET environment are executed in a CLR application domain, an isolated execution and security boundary within a process; and application configuration information is scoped to application domains not the application process itself. Your provider basically tries to find the configuration information (a.k.a. connection string) from the currently running application domain. Saying that, we can then create a new application domain in our process, make it point to the configuration file of our choice (A SharePoint Web Application Web.Config), instantiate the provider in its own application domain, then remotely call the instance (you can only call object in different application domain through .NET Remoting). Ok, don&rsquo;t be sweating on me now, it&rsquo;s quite straight forward and that&rsquo;s what the CAMAP model simplifies.</span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">The following is a diagram that depicts the important components of the CAMAP model:</span></p>
<p><span style="FONT-FAMILY: verdana, geneva"><span style="FONT-SIZE: medium"><span style="LINE-HEIGHT: 115%"><img src="http://community.bamboosolutions.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/french/The-CAMAP-Model-Diagram.jpg" border="0" alt="" /><br /></span></span></span></p>
<p>&nbsp;</p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">The provider runtime is so to say, the center of gravity for the model, clients first interface to it to get a membership provider; it hides all the complexity behind creating application domains, finding farm wide membership provider definitions, creating remotable membership providers, routing calls to an actual concrete membership providers, and managing a runtime pool.</span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">Clients just call a static method to get a membership runtime object to get a membership provider like this:</span></p>
<p align="left"><span style="FONT-SIZE: small"><span style="FONT-FAMILY: verdana, geneva"><span style="COLOR: #2b91af">IMembershipRuntime</span> runtime = <span style="COLOR: #2b91af">MembershipRuntime</span>.GetMembershipRuntime(<span style="COLOR: #a31515">"http://SharePointSiteUrl"</span>, <span style="COLOR: #a31515">"providername"</span>); <br /></span></span></p>
<p align="left"><span style="FONT-FAMILY: verdana, geneva"><span style="FONT-SIZE: medium"><span style="FONT-SIZE: small"><span style="LINE-HEIGHT: 115%">System.Web.Security.<span style="COLOR: #2b91af">MembershipProvider</span> mp = runtime.MembershipProvider;</span></span></span></span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">As you can see, the membership provider is of type System.Web.Security.MembershipProvider, a type all membership providers inherits from. You would call it the same way you would call any other membership provider; behind the scene though, it goes through a couple of proxies that hides the details of loading application domain, .NET remoting and resource pooling.</span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">The first time you get a runtime object for a specific provider, the runtime creates a new application domain where the actual membership provider will eventually run; this operation is not as slow as creating a new process but it is indeed expensive operation, that&rsquo;s why the runtime for each membership provider is resource pooled to improve performance. Ones they have been created they will remain in your application memory space, until its provider definition has been changed or the application itself has restarted. The runtime pool which is actually the entity that handles the resource pooling, makes sure the runtime objects are kept in memory and up-to-date.</span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">Use the MembershipRuntime factory method to instantiate membership providers, and you will be unleashed to the ability to administer and manage membership data across a SharePoint farm from a central web application and ability to access membership data from non-web application contexts. </span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">As it is an initial implementation, it has limitations. It only supports remoting for the MembershipProvider class, but not for the MembershipUser and MembershipUserCollection, but you can actually use the same principles used on the MembershipProvider class and apply it on MembershipUser and MembershipUserCollection classes. And, the model is not taking into consideration the possibility that configuration sections in the Web.Config can be encrypted. For this case, you are going to have to run each membership runtime under the security context of the application pool identity (assuming that the application pool identity is used to encrypt the configuration sections).</span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">The following patterns are the most important design patterns used in the CAMAP model: Proxy Pattern, Singleton Pattern, Factory Method Pattern, and Adapter Pattern. Understanding of the design patterns is vital to understanding how the CAMAP model internally works and will help you out if you want to customize it for your own use. In future posts, I might explain the internal implementation in terms of the design patterns that helped me realize the model, till then you can start reading about the design patterns I used at <a href="http://sourcemaking.com/design_patterns/" target="_blank">Source Making - Design Patterns</a> and then dive in the implementation on your own. </span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">To k-map,</span></p>
<p><span style="FONT-FAMILY: 'Calibri', 'sans-serif'; FONT-SIZE: 12pt; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">NaT</span></p>]]></content></entry><entry><title>Security Trimmed Custom Actions</title><category term="Application Pages"/><category term="Security"/><category term="SharePoint"/><category term="SharePoint Security"/><id>http://www.usingnat.net/sharepoint/2008/11/16/security-trimmed-custom-actions.html</id><link rel="alternate" type="text/html" href="http://www.usingnat.net/sharepoint/2008/11/16/security-trimmed-custom-actions.html"/><author><name>NaT</name></author><published>2008-11-16T05:00:00Z</published><updated>2008-11-16T05:00:00Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p class="MsoNormal" style="margin:0in 0in 10pt;text-align:justify;"><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">In my <a class="null" title="Securing SharePoint Application Pages" href="http://natnael.squarespace.com/sharepoint/2009/4/28/securing-sharepoint-application-pages.html" target="_blank">Securing SharePoint Application Pages</a> post, I showed you how to check for SharePoint permissions, and custom permissions in a custom application page. But we did not deal with custom actions security. </span></p>
<p class="MsoNormal" style="margin:0in 0in 10pt;text-align:justify;"><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">Most of the time application pages are clicked-through from custom actions. You might be clicking a link from the site settings page or a menu item from the site actions menu and navigating to an application page, only to get an access denied error message if you are not authorized to use the application page. So, custom actions should also be security trimmed. Adding security to custom actions is quite simple, just add the &ldquo;Rights&rdquo; attribute and list all the SharePoint permissions you need to check in the element manifest file. Then your custom action user interface will only show up when user is authorized to hit the application page.</span></p>
<p>&nbsp;</p>
<div>
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">&lt;?</span><span style="color:#800000;">xml</span> <span style="color:#ff0000;">version</span><span style="color:#0000ff;">="1.0"</span> <span style="color:#ff0000;">encoding</span><span style="color:#0000ff;">="utf-8"</span>?<span style="color:#0000ff;">&gt;</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Elements</span> <span style="color:#ff0000;">xmlns</span><span style="color:#0000ff;">="http://schemas.microsoft.com/sharepoint/"</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">CustomAction</span> <span style="color:#ff0000;">Id</span><span style="color:#0000ff;">="AppPageNavigationMenu"</span> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#ff0000;">GroupId</span><span style="color:#0000ff;">="SiteActions"</span> </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#ff0000;">Location</span><span style="color:#0000ff;">="Microsoft.SharePoint.StandardMenu"</span> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#ff0000;">Sequence</span><span style="color:#0000ff;">="1001"</span> </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#ff0000;">Title</span><span style="color:#0000ff;">="AppPage"</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#ff0000;">Description</span><span style="color:#0000ff;">="Navigate to AppPage"</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#ff0000;">Rights</span><span style="color:#0000ff;">="BrowseUserInfo,CreateGroups,ManageLists"</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">UrlAction</span> <span style="color:#ff0000;">Url</span><span style="color:#0000ff;">="~sitecollection/_layouts/ApplicationPageSecurity/AppPage.aspx"</span> <span style="color:#0000ff;"> /&gt;</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">CustomAction</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Elements</span><span style="color:#0000ff;">&gt;</span></pre>
</div>
&nbsp;</div>
<p class="MsoNormal" style="margin:0in 0in 10pt;text-align:justify;"><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">Don&rsquo;t be too happy, what about the custom permissions we wanted to check? You cannot put that in the element manifest file! But you can actually use your own custom security trimmed web control that your custom action can use to render itself. In the SharePoint Object model there is one Web control we can take advantage of, that is SPSecurityTrimmedControl from Microsoft.SharePoint.WebControls namespace. As its name implies, the control has the ability to check for SharePoint permissions and hides itself when a user does not have enough permission to use the custom action.</span></p>
<p class="MsoNormal" style="margin:0in 0in 10pt;text-align:justify;"><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">The key property in the SPSecurityTrimmedControl that will do the trick is a Boolean internal property named &ldquo;ShouldRender&rdquo;. SPSecurityTrimmedControl checks for SharePoint permissions and if user does not meet them, it sets ShouldRender to false, then skips the rendering part and makes itself invisible. </span></p>
<pre style="text-align:justify;"><strong><span style="font-size:11pt;color:#4f6228;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;mso-themecolor:accent3;mso-themeshade:128;">Render from SPSecurityTrimmedControl (</span></strong><span style="font-size:11pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">Thanking Red Gate&rsquo;s .NET Reflector<strong><span style="color:#4f6228;mso-themecolor:accent3;mso-themeshade:128;">):</span></strong></span></pre>
<div>
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> Render(HtmlTextWriter output)    </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">{</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">this</span>.ShouldRender)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        {</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">base</span>.Render(output);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        }</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">}</pre>
</div>
</div>
<p><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">In fact, it is the ShouldRender property itself that makes sure that the user is authorized. So it comes down to this: you inherit from SPSecurityTrimmedControl, assign Permissions property with your new SharePoint permissions before ShouldRender is called (on OnInit will do), and only render if user passes through the SharePoint Permissions and your custom access check logic by overriding Render. Finally, in the element manifest file, refer to the class and assembly the security trimmed control is defined in. And, this is what you should get:</span></p>
<pre style="text-align:justify;"><strong><span style="font-size:12pt;color:#4f6228;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;mso-themecolor:accent3;mso-themeshade:128;">Manifest File referring to a custom control</span></strong></pre>
<div>
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">&lt;?</span><span style="color:#800000;">xml</span> <span style="color:#ff0000;">version</span><span style="color:#0000ff;">="1.0"</span> <span style="color:#ff0000;">encoding</span><span style="color:#0000ff;">="utf-8"</span>?<span style="color:#0000ff;">&gt;</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Elements</span> <span style="color:#ff0000;">xmlns</span><span style="color:#0000ff;">="http://schemas.microsoft.com/sharepoint/"</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">CustomAction</span> <span style="color:#ff0000;">Id</span><span style="color:#0000ff;">="AppPageNavigationMenu"</span> </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#ff0000;">GroupId</span><span style="color:#0000ff;">="SiteActions"</span> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#ff0000;">Location</span><span style="color:#0000ff;">="Microsoft.SharePoint.StandardMenu"</span> </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#ff0000;">ControlAssembly</span><span style="color:#0000ff;">="Bamboo.ApplicationPageSecurity, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8c72b2.."</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#ff0000;">ControlClass</span><span style="color:#0000ff;">="Bamboo.ApplicationPageSecurity.WebControls.AppPageActionControl"</span> <span style="color:#0000ff;"> /&gt;</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Elements</span><span style="color:#0000ff;">&gt;</span></pre>
</div>
</div>
<pre style="text-align:justify;"><strong><span style="font-size:12pt;color:#4f6228;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;mso-themecolor:accent3;mso-themeshade:128;mso-no-proof:yes;">Custom Security Trimmed Control</span></strong><strong></strong></pre>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">using</span> System;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">using</span> System.Collections.Generic;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">using</span> System.Text;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">using</span> Microsoft.SharePoint.WebControls;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">using</span> Microsoft.SharePoint.Utilities;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">using</span> Microsoft.SharePoint;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">using</span> System.Reflection;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">namespace</span> Bamboo.ApplicationPageSecurity.WebControls</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">{</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> AppPageActionControl : SPSecurityTrimmedControl</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    {</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">protected</span> MenuItemTemplate menuItem;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">bool</span> shouldRender = <span style="color:#0000ff;">false</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">bool</span> CustomShouldRender</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        {</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            get</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            {</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#0000ff;">bool</span> hasCustomRights = <span style="color:#0000ff;">this</span>.HasCustomRights();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                Type baseType = <span style="color:#0000ff;">this</span>.GetType().BaseType;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#0000ff;">object</span> obj = baseType.InvokeMember(</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                    <span style="color:#006080;">"ShouldRender"</span>, </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                    BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Instance,</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                    <span style="color:#0000ff;">null</span>, <span style="color:#0000ff;">this</span>, <span style="color:#0000ff;">new</span> <span style="color:#0000ff;">object</span> [] {});</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#0000ff;">if</span> (obj != <span style="color:#0000ff;">null</span>)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                {</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                    <span style="color:#0000ff;">return</span> (<span style="color:#0000ff;">bool</span>)obj &amp;&amp; hasCustomRights;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                }</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#0000ff;">else</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                {</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                    <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                }</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        }</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">virtual</span> SPBasePermissions AppPagePermissions</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            get</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                SPBasePermissions permissions = <span style="color:#0000ff;">base</span>.Permissions </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                | SPBasePermissions.ViewFormPages <span style="color:#008000;">// Don't forget this, if custom action takes to an application page</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                | SPBasePermissions.BrowseUserInfo</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                | SPBasePermissions.CreateGroups</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                | SPBasePermissions.ManageLists;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#0000ff;">return</span> permissions;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        }</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">bool</span> HasCustomRights()</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">bool</span> hasCustomRights = <span style="color:#0000ff;">false</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#008000;">//write here a custom logic to check if user has enough rights to access application page</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#008000;">//if yes, set userCheckedForCustomLogic to true;</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            hasCustomRights = <span style="color:#0000ff;">true</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">return</span> hasCustomRights;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> SetAppPagePermissionProperties()</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        {</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">base</span>.Permissions = <span style="color:#0000ff;">this</span>.AppPagePermissions;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#008000;">// DoesUserHavePermission is called on the current SPWeb</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">base</span>.PermissionContext = PermissionContext.CurrentSite;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#008000;">// It make sure user have all permissions</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">base</span>.PermissionMode = PermissionMode.All;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#008000;">//By default any users (included AnonymousUsersOnly), but I only wanted to deal with Authenticated Users only</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">base</span>.AuthenticationRestrictions = AuthenticationRestrictions.AuthenticatedUsersOnly;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> CreateAndAddMenuItem()</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        {</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">this</span>.menuItem = <span style="color:#0000ff;">new</span> MenuItemTemplate();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">this</span>.menuItem.Title = <span style="color:#006080;">"AppPage"</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">this</span>.menuItem.Text = <span style="color:#006080;">"AppPage"</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">this</span>.menuItem.Description = <span style="color:#006080;">"AppPage Description"</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">this</span>.menuItem.Sequence = 1040;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">this</span>.menuItem.ClientOnClickNavigateUrl = <span style="color:#006080;">"~site/_layouts/Bamboo.ApplicationPageSecurity/AppPage.aspx"</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">this</span>.Controls.Add(menuItem);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        }</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> OnInit(EventArgs e)</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        { </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">this</span>.SetAppPagePermissionProperties();</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">base</span>.OnInit(e);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        }</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> OnLoad(EventArgs e)</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">base</span>.EnsureChildControls();</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">base</span>.OnLoad(e);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        }</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> CreateChildControls()</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">this</span>.CreateAndAddMenuItem();</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> OnPreRender(EventArgs e)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        {</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">base</span>.OnPreRender(e);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">this</span>.CustomShouldRender == <span style="color:#0000ff;">true</span>)</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#0000ff;">this</span>.shouldRender = <span style="color:#0000ff;">true</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">else</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#0000ff;">this</span>.shouldRender = <span style="color:#0000ff;">false</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#0000ff;">base</span>.Visible = <span style="color:#0000ff;">false</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            }</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> Render(System.Web.UI.HtmlTextWriter output)</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">this</span>.shouldRender == <span style="color:#0000ff;">true</span>)</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#0000ff;">base</span>.Render(output);</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">else</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                <span style="color:#0000ff;">base</span>.Visible = <span style="color:#0000ff;">false</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        }</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">}</pre>
</div>
</div>
<p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;mso-layout-grid-align:none;"><span style="font-size:12pt;font-family:'Courier New';mso-no-proof:yes;">&nbsp;</span></p>
<p class="MsoNormal" style="margin:0in 0in 10pt;text-align:justify;"><span style="font-size:12pt;line-height:115%;"><span style="font-family:calibri;">Yes I know, am using reflection to read an internal property, and that breaks encapsulation. Unlikely that it will dissappear one day, but you can always write yourself a routine that checks for the SharePoint permissions and avoids calling ShouldRender but, then again, why the need to inherit from SPSecurityTrimmedControl in the first place? Mais Voila! You have a security trimmed custom action with SharePoint permissions and custom permissions checking ability (and that is what we want). </span></span></p>
<p class="MsoNormal" style="margin:0in 0in 10pt;text-align:justify;"><span style="font-size:12pt;line-height:115%;"><span style="font-family:calibri;">Sincerely your code,</span></span></p>
<p class="MsoNormal" style="margin:0in 0in 10pt;text-align:justify;"><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">NaT</span></p>]]></content></entry><entry><title>Multiple Event Receiver and The Single-Responsibility Principle (SRP)</title><category term="Advanced SharePoint"/><category term="Multiple Feature Receiver"/><category term="Single Responsibility Principle"/><id>http://www.usingnat.net/sharepoint/2008/10/16/multiple-event-receiver-and-the-single-responsibility-princi.html</id><link rel="alternate" type="text/html" href="http://www.usingnat.net/sharepoint/2008/10/16/multiple-event-receiver-and-the-single-responsibility-princi.html"/><author><name>NaT</name></author><published>2008-10-16T04:13:00Z</published><updated>2008-10-16T04:13:00Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>SharePoint OOTB deployment functionalities are quite limited, and as developers we always end up filling the gaps ourselves. You might need to write code to clean up Web Part galleries, deploy resource files, or update Web.Config files (perhaps to register an Http Module), basically do some extra stuff to have a complete solution deployment (or retraction), and most of the time you end up writing a Feature receiver class to undergo a taskon Feature installed, activated, deactivating or uninstalling event handlers.</p>
<p>When writing a Feature event receiver class, you might be tempted to write all your code in a single Feature eventreceiver, or assign additional responsibilities to your existing Feature event receiver class. Maybe it&rsquo;s not even temptation; when you think about it, the only thing you have to change is the Feature event receiver assembly that the Feature manifest is pointing to, and doing so might seem to make sense. But it definitely violates one of the most important principles of software development (a.k.a. Computer Science), the Single-Responsibility Principle (SRP), which statesthat, &ldquo;<em>there should never be more than one reason for a class to change</em>&rdquo;. Tom DeMarco mentioned SRP in his book, <span style="COLOR: #31849b"><em><a class="null" href="http://en.wikipedia.org/wiki/Structured_Systems_Analysis_and_Design_Methodology" target="_blank">Structured Analysis and Systems Specification</a></em></span>, back in 1979, and till now I've tended to break it ;). Ok, I wasn&rsquo;t even born then, but it says:</p>
<p><span><span style="COLOR: #31849b"><em><span style="COLOR: #000000">&ldquo;...every object should have a single responsibility, and that all its services should be narrowly aligned with that responsibility.&ldquo;</span></em></span></span></p>
<p>Why is it important to separate responsibilities into separate classes?</p>
<p>Extracts from <a class="null" href="http://www.objectmentor.com/resources/articles/srp.pdf" target="_blank">http://www.objectmentor.com/resources/articles/srp.pdf</a>, a chapter just about SRP:</p>
<p><span style="COLOR: #4f6228"><em><span style="COLOR: #000000">&ldquo;...Because each responsibility is an axis of change... If a class assumes more than one responsibility, then there will be more than one reason for it to change. If a class has more than one responsibility, then the responsibilities become coupled. Changes to one responsibility may impair or inhibit the class&rsquo; ability to meet the others. This kind of coupling leads to fragile designs that break in unexpected ways when changed...&rdquo;</span></em></span></p>
<p>All right, taking SRP into consideration, I decided to have the different set of functions I needed to execute in different Feature receivers. But wait a minute! You cannot have <strong>multiple Feature eventreceivers</strong> for a single Feature. How about we have a main Feature manifest that is pointing to a main Feature event receiver, and list down all the other Feature event receiver classes as Feature properties. When the main Feature event receiver goes through its life cycle, it will instantiate and execute the other Feature eventreceiver classes, per event (you have to write custom code to instantiate and execute the other Features). It sounds like a feasible solution, but it also sounds bizarre to me tohave Feature eventreceiver classes with no actual Feature definition. Ok, instead, let me have a hidden Feature definition for each Feature event receiver class, and have activation dependencies on the main Feature. That way, there is no need for you to broadcast the main Feature&rsquo;s life cycle events to the other ones yourself, because SharePoint will take care of that through Feature activation dependency (If you're undergoing tasks on Featureinstalled or Uninstalling then there is no need to have activation dependency; the feature definitionswouldjust need to be referred in the solution manifest file so they can just be installed and removed). Also, you will be able to have isolated test cases for the other Feature event receiver classes without really making a lot of changes because they have their own Feature manifest file that you can use (ok, it might not be a big deal).</p>
<p>It should look something like this:</p>
<p style="TEXT-INDENT: 0in; MARGIN: 0in 0in 10pt"><span><span style="COLOR: #000000"><span style="FONT-SIZE: small"><span style="FONT-FAMILY: Calibri">Main Feature Manifest file</span></span></span></span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">&lt;?</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #a31515">xml</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff"> </span><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">version</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="COLOR: blue">1.0</span>"<span style="COLOR: blue"> </span><span style="COLOR: red">encoding</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">utf-8</span>"<span style="COLOR: blue"> ?&gt;</span></span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">&lt;</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #a31515">Feature</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff"> </span><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">Id</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"</span><span style="FONT-FAMILY: Calibri; FONT-SIZE: small"> </span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">8B44F613-6040-4777-AE4F-16D56AB26D19</span><span style="FONT-FAMILY: 'Courier New'">"</span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">Title</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="COLOR: blue">Main Feature</span>"</span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">Description</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"A visible Feature that the end-user going to activate and deactivate"</span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">Version</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="COLOR: blue">1.0.0.0</span>"</span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">Scope</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="COLOR: blue">WebApplication</span>"</span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">Hidden</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="COLOR: blue">false</span>"</span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">xmlns</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="COLOR: blue">http://schemas.microsoft.com/sharepoint/</span>"<span style="COLOR: blue">&gt;</span></span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">&lt;</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #a31515">ActivationDependencies</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">&gt;</span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">&lt;</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #a31515">ActivationDependency</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff"> </span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">FeatureId</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="BACKGROUND: aqua; COLOR: blue; mso-highlight: aqua">528DD2D9-DC76-45a1-8E2F-DFC57B4CC226</span>"<span style="COLOR: blue"> /&gt;</span></span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0.5in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">&lt;</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #a31515">ActivationDependency</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff"> </span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">FeatureId</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="COLOR: blue">7C5BEB3F-2129-4e12-BADB-22763FBF6758</span>"<span style="COLOR: blue"> /&gt;</span></span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0.5in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">&lt;</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #a31515">ActivationDependency</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff"> </span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">FeatureId</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="COLOR: blue">E4E20B37-13EC-44cd-9BB1-6514F1AA311F</span>"<span style="COLOR: blue"> /&gt;</span></span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">&lt;/</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #a31515">ActivationDependencies</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">&gt;</span></p>
<p style="TEXT-INDENT: 0in; MARGIN: 0in 0in 10pt"><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">&lt;/</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #a31515">Feature</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">&gt;</span></p>
<p style="TEXT-INDENT: 0in; MARGIN: 0in 0in 10pt"><span style="FONT-FAMILY: Calibri; FONT-SIZE: small">Dependent Feature Manifest file</span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">&lt;?</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #a31515">xml</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff"> </span><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">version</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="COLOR: blue">1.0</span>"<span style="COLOR: blue"> </span><span style="COLOR: red">encoding</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">utf-8</span>"<span style="COLOR: blue"> ?&gt;</span></span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">&lt;</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #a31515">Feature</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff"> </span><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">Id</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="BACKGROUND: aqua; COLOR: blue; mso-highlight: aqua">528DD2D9-DC76-45a1-8E2F-DFC57B4CC226</span>"</span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">Title</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="COLOR: blue">Dependent Feature</span>"</span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">Description</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="COLOR: blue">Hidden dependent Feature with its own Feature receiver, and activate/deactivated when the main Feature is</span>"</span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">Version</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="COLOR: blue">1.0.0.0</span>"</span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">Scope</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="COLOR: blue">WebApplication</span>"</span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="BACKGROUND-COLOR: #00ff00"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">Hidden</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="COLOR: blue">true</span>"</span></span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">ReceiverAssembly</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"[Feature receiver assembly name here]"<span style="mso-spacerun: yes"> </span></span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">ReceiverClass</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"[Feature receiver class here]"</span></p>
<p style="TEXT-ALIGN: left; LINE-HEIGHT: normal; TEXT-INDENT: 0in; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" align="left"><span style="FONT-FAMILY: 'Courier New'; COLOR: #ff0000">xmlns</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">=</span><span style="FONT-FAMILY: 'Courier New'">"<span style="COLOR: blue">http://schemas.microsoft.com/sharepoint/</span>"<span style="COLOR: blue">&gt;</span></span></p>
<p style="TEXT-INDENT: 0in; MARGIN: 0in 0in 10pt"><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">&lt;/</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #a31515">Feature</span><span style="FONT-FAMILY: 'Courier New'; COLOR: #0000ff">&gt;</span></p>
<p>I agree thatittakes a little extra work to have a separate Feature receiver class and Feature manifest file for each dependent Feature, but for the sake of SRP and Tom DeMarco, I think it is totally worth it. Even though the Single-Responsibility Principle is the simplest principle of all, in most situations it is kind of hard to identify SRP violations. Keeping in mind to work underthe circumstances which best suit your own needs, know that having a separate Feature event receiver class for each set of functions at least reduces complexity so that others know where to look into an organized complexity.</p>
<p>To SRP,</p>
<p>NaT</p>]]></content></entry><entry><title>Securing SharePoint Application Pages</title><category term="Application Pages"/><category term="Custom Actions"/><category term="Security"/><category term="SharePoint"/><category term="SharePoint Security"/><id>http://www.usingnat.net/sharepoint/2008/10/16/securing-sharepoint-application-pages.html</id><link rel="alternate" type="text/html" href="http://www.usingnat.net/sharepoint/2008/10/16/securing-sharepoint-application-pages.html"/><author><name>NaT</name></author><published>2008-10-16T03:53:00Z</published><updated>2008-10-16T03:53:00Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">Why inherit from LayoutsPageBase to write a custom application page?&nbsp; It&rsquo;s actually to take advantage of the security elements LayoutsPageBase adds on top of UnsecuredLayoutsPageBase. If only if we wanted to have an application page we would have just inherited UnsecuredLayoutsPageBase, and boom, we&rsquo;ll have a custom ASP.NET page under the context of SharePoint.</span></p>
<div></div>
<p class="MsoNormal" style="margin:0in 0in 10pt;text-align:justify;"><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">The very reason we call inheritance, white box reuse, is because we assume that we understand how the base class (the white box) works and then we take advantage by reusing its inherit functionalities. So, I tried to understand how security is implemented in LayoutsPageBase so I can efficiently customize it.</span></p>
<p class="MsoNormal" style="margin:0in 0in 10pt;text-align:justify;"><strong><span style="font-size:12pt;color:#4f6228;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;mso-themecolor:accent3;mso-themeshade:128;">Microsoft.SharePoint.WebControls.LayoutsPageBase</span></strong></p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">namespace</span> Microsoft.SharePoint.WebControls
{
    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> LayoutsPageBase : UnsecuredLayoutsPageBase
    {
        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">readonly</span> SPBasePermissions DefaultLayoutsRights;
        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">virtual</span> <span style="color:#0000ff;">bool</span> RequireDefaultLayoutsRights { get; }
        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">virtual</span> <span style="color:#0000ff;">bool</span> RequireSiteAdministrator { get; }
        <span style="color:#0000ff;">protected</span> LayoutsPageBase.RightsCheckModes RightsCheckMode { get; set; }
        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">virtual</span> SPBasePermissions RightsRequired { get; }
        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">void</span> CheckRights();
        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> OnLoad(EventArgs e);
        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> OnLoadComplete(EventArgs e);
        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> OnPreInit(EventArgs e);
 
        [Flags]
        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">enum</span> RightsCheckModes
        {
            None = 0,
            OnPreInit = 1,
            OnLoadComplete = 2,
        }
    }
}
</pre>
</div>
<p class="MsoNormal" style="text-align: left; margin: 0in 0in 10pt;"><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">You have two options as to when to check users&rsquo; permission to access your application page: OnLoadComplete and on OnPreInit. By default, permissions are checked on OnLoadComplete, and the default permissions checked are </span><span style="font-size:12pt;"><a title="SPBasePermissions Microsoft.SharePoint.SPBasePermissions.EmptyMask;" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Microsoft.SharePoint:12.0.0.0:71e9bce111e9429c/Microsoft.SharePoint.SPBasePermissions/EmptyMask"><span style="color:windowtext;font-family:'Calibri','sans-serif';text-decoration:none;mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;text-underline:none;">EmptyMask</span></a></span><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">, </span><span style="font-size:12pt;"><a title="SPBasePermissions Microsoft.SharePoint.SPBasePermissions.ViewPages;" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Microsoft.SharePoint:12.0.0.0:71e9bce111e9429c/Microsoft.SharePoint.SPBasePermissions/ViewPages"><span style="color:windowtext;font-family:'Calibri','sans-serif';text-decoration:none;mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;text-underline:none;">ViewPages</span></a></span><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">,<span style="mso-spacerun:yes;">&nbsp; </span></span><span style="font-size:12pt;"><a title="SPBasePermissions Microsoft.SharePoint.SPBasePermissions.Open;" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Microsoft.SharePoint:12.0.0.0:71e9bce111e9429c/Microsoft.SharePoint.SPBasePermissions/Open"><span style="color:windowtext;font-family:'Calibri','sans-serif';text-decoration:none;mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;text-underline:none;">Open</span></a></span><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;"> and </span><span style="font-size:12pt;"><a title="SPBasePermissions Microsoft.SharePoint.SPBasePermissions.ViewFormPages;" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Microsoft.SharePoint:12.0.0.0:71e9bce111e9429c/Microsoft.SharePoint.SPBasePermissions/ViewFormPages"><span style="color:windowtext;font-family:'Calibri','sans-serif';text-decoration:none;mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;text-underline:none;">ViewFormPages</span></a></span><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;"> site permissions, which I find to be the minimum permission set you need to access a SharePoint application page. If you don&rsquo;t want the default permissions to be checked you just need to override <span style="mso-bidi-font-weight:bold;">RequireDefaultLayoutsRights</span> and return false. Of course, checking the default permissions will not do you too much good, you might also want to check if user has enough rights to manage alerts, create groups or check any of the SharePoint permissions to accomplish a specific business use case. That is where overriding RightsRequired property comes in. Simply by overriding it and returning all the permissions you need to check, SharePoint will take care the rest for you by checking the permissions you listed including the default layouts permissions and authorize the user to access the custom application page and if checking fails SharePoint redirects the user to an access denied page and let the user login with a different account.</span></p>
<p class="MsoNormal" style="text-align: left; line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">&nbsp;</p>
<p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;mso-layout-grid-align:none;"><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">It sounds almost perfect now. But, what if you wanted to check if a user belongs to a certain security group in Active Directory or check if user belongs to a SharePoint Group before granting access? Well, there is no SharePoint permission (SPBasePermission) that directly corresponds to that, so there is no use in just using RightsRequired property. But then I could have overridden CheckRights and put my custom user access check logic in there if it was a virtual method, unfortunately it is not. </span></p>
<p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;mso-layout-grid-align:none;">&nbsp;</p>
<p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;mso-layout-grid-align:none;"><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">What about RequireSiteAdministrator? I assumed if supposedly it was returning true, then you would be required to be a site administrator to access the page. This was not actually the case. Whether or not you are a site administrator, it will not let you access it if it was returning true. So, what does that leave me with? I could perhaps put logic in there and return true every time my user does not pass through my custom permission check logic, right? But it still kind of bothered me that it my might be a little confusing to do so. So I kind of looked back and asked myself why don&rsquo;t I just put my dumb custom logic on OnLoad (and redirect user to access denied page when they do not meet my custom permissions), and change RightsCheckMode to OnPreInit so that SharePoint permissions are checked before my custom checks are run (Didn&rsquo;t know it was that simple), and this is what you should get: </span></p>
<p>&nbsp;</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> AppPage : LayoutsPageBase</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">{     </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> SPBasePermissions RightsRequired</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    {</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        get</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        {</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            SPBasePermissions permissions = <span style="color:#0000ff;">base</span>.RightsRequired </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                | SPBasePermissions.BrowseUserInfo </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                | SPBasePermissions.CreateGroups</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">                | SPBasePermissions.ManageLists;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            <span style="color:#0000ff;">return</span> permissions;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        }</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color:#0000ff;">public</span> AppPage()</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    {</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">this</span>.RightsCheckMode = RightsCheckModes.OnPreInit;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    }</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">virtual</span> <span style="color:#0000ff;">void</span> CheckCustomRights()</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">bool</span> userCheckedForCustomLogic = <span style="color:#0000ff;">false</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#008000;">//write here a custom logic to check if user has enough rights to access application page</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#008000;">//if yes, set userCheckedForCustomLogic to true;</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">if</span> (!userCheckedForCustomLogic)</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            SPUtility.HandleAccessDenied(<span style="color:#0000ff;">new</span> UnauthorizedAccessException());</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    }</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> OnLoad(EventArgs e)</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color:#0000ff;">this</span>.CheckCustomRights();   </pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">}</pre>
</div>
</div>
<p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;mso-layout-grid-align:none;">&nbsp;</p>
<p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;mso-layout-grid-align:none;"><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;"><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">I admit that, I kind of exaggerated the process to getting to the solution. But, I wanted to make an important point that if you ask yourself why you are inheriting anything, at all times, then you will be able to efficiently reuse code (and you should get a tattoo just saying that).</span></span></p>
<p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;mso-layout-grid-align:none;">&nbsp;</p>
<p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;mso-layout-grid-align:none;"><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;"><span style="font-size:12pt;font-family:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;">using(NaT)</span></span></p>]]></content></entry></feed>
