<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:thr='http://purl.org/syndication/thread/1.0' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-1850047779793623762</atom:id><lastBuildDate>Thu, 28 Jul 2011 21:00:22 +0000</lastBuildDate><title>DotNetIdeas</title><description>.NET Framework/Compact Framework and SharePoint Programming Tips and Tricks</description><link>http://dotnetideasblog.blogspot.com/search/label/SharePoint</link><managingEditor>noreply@blogger.com (DotNetIdeas)</managingEditor><generator>Blogger</generator><openSearch:totalResults>15</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-792165452202514980</guid><pubDate>Fri, 13 Aug 2010 21:45:00 +0000</pubDate><atom:updated>2010-08-13T14:45:27.756-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>Avoid Polluting SharePoint farm</title><description>&lt;p&gt;A developer can easily pollute a SharePoint farm by exposing components to unintended audience as the following.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;In MOSS, you cannot target a feature to a specific site, site collection or web application. A deployed feature is visible to SharePoint administrators everywhere in the SharePoint Farm even though the feature should be used in a very specific context.&lt;/li&gt;    &lt;li&gt;Deploying a Dll to GAC makes the Dll fully trusted and accessible to the entire server. Any code running on the server may use the Dll.&lt;/li&gt;    &lt;li&gt;A user control deployed to the ControlTemplates directory can be used by any ASP.NET components deployed to the farm.&lt;/li&gt;    &lt;li&gt;An application page deployed to the Layouts directory is visible to end users from any SharePoint site in the Farm. Most importantly, you cannot manage the security permission on the Page easily. The page will observe the default security permission for all the pages in Layouts directory. Also, the code behind dll for an application page has to have full trust since everything in Layout has full trust. This violates the basic security principle. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Item 4 will do the most damage since end users will see the pollution right way and it is not easy to apply security to the page to fix it. Item 1 will only affect SharePoint administrators. Item 2 and 3 will affect developers and infrastructure team.&lt;/p&gt;  &lt;p&gt;However, Item 4 is the least aware among developers since it is just so easy.&lt;/p&gt;  &lt;p&gt;An alternative to create an application page is to deploy the page to a document library in the site needing the page. Because it is in a document library, you can apply different security policies to the page. So only the right people can access the page with the right permissions. Also, the code behind dll of it can be deployed to bin directory without full trust since it is not in Layouts directory. Obviously, this approach solves all the issues listed in Item 4.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-792165452202514980?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2010/08/avoid-polluting-sharepoint-farm.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-8886743894361413238</guid><pubDate>Wed, 24 Feb 2010 18:00:00 +0000</pubDate><atom:updated>2010-04-12T14:44:22.104-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>Access external data in SharePoint with BDC (business data catalog), SSO (Single Sign On) and WCF (Windows Communication foundation)</title><description>&lt;pre class="csharpcode"&gt;&amp;#160;&lt;/pre&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_ElXg_EOWn5c/S4VpHb_N1pI/AAAAAAAAAgU/WqMdS39DTO4/s1600-h/image4.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="193" alt="image" src="http://lh5.ggpht.com/_ElXg_EOWn5c/S4VpHnYh-TI/AAAAAAAAAgY/kurQEtad0hs/image_thumb2.png?imgmax=800" width="554" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;High Level Summary&lt;/h3&gt;

&lt;p&gt;Accessing external systems from SharePoint portals is a typical integration scenario. One reality that has not changed is that there are three basic components to any interoperability scheme.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;b&gt;Communication&lt;/b&gt;&amp;#8211;You must be able to connect and communicate with the foreign system, either through code or through infrastructure. &lt;/li&gt;

  &lt;li&gt;&lt;b&gt;Identity Management&lt;/b&gt;&amp;#8211;You must have some way to authenticate users against the foreign system. &lt;/li&gt;

  &lt;li&gt;&lt;b&gt;Composition&lt;/b&gt;&amp;#8211;You must be able to assemble discrete pieces of data (from tables, function calls, and so on) into an entity that is meaningful and useful to business users. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are challenges in all three of these activities, regardless of what you are connecting. &lt;/p&gt;

&lt;p&gt;The architecture tackles the four issues elegantly. WCF provides the communication. Single Sign On provides the Identity management. Business data catalog allows different ways to compose such as DataViewWebPart, BDC object model, search and out-of-box BDC web parts. &lt;/p&gt;

&lt;p&gt;Comparing with directly accessing WCF web service, my favorite&amp;#160; argument to support this architecture is that BDC is a layer of security boundary in addition to its support to search. BDC allows you to authorize the access to BDC entities through Shared Service web pages. With direct WCF access, there is no easy way to achieve this level of seamless integration and flexibility to control the authorization. &lt;/p&gt;

&lt;p&gt;Another advantage of this architecture is to let BDC access external data through SSO, which allows the management of&amp;#160; identities in SharePoint central admin web pages. Invoking WCF or Web Service directly from code will run into the famous double hop issue in a distributed environment unless you hard code the user credentials.&amp;#160; The matter will be even more complicated if you use SharePoint&amp;#160; Form Authentication. BDC has very nice integration with SSO so it is a very nature approach to marry those two technologies together for accessing external data.&lt;/p&gt;

&lt;h3&gt;Implementation Details&lt;/h3&gt;

&lt;p&gt;Notice, it is not a step by step tutorial. Instead, it covers important ideas and possible catches during implementation.&lt;/p&gt;

&lt;h4&gt;Tools&lt;/h4&gt;

&lt;ol&gt;
  &lt;li&gt;Visual Studio 2008 for WCF development &lt;/li&gt;

  &lt;li&gt;Microsoft Application Definition Designer for BDC definition. &lt;/li&gt;

  &lt;li&gt;Microsoft MOSS server for SSO and BDC configuration &lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;&lt;/h4&gt;

&lt;h4&gt;Ideas/Catches&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;h5&gt;Use BDC to control the authorization. In the home page of the ShareService administration web site, you will see the &amp;#8220;Business data catalog permission&amp;#8221; at the bottom-right corner as the following &lt;/h5&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
  &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/S4VpH1NNz9I/AAAAAAAAAgc/RfflAsDWlWo/s1600-h/image7.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="150" alt="image" src="http://lh6.ggpht.com/_ElXg_EOWn5c/S4VpIBw4R6I/AAAAAAAAAgg/t8j1MKzZvyg/image_thumb3.png?imgmax=800" width="235" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;h5&gt;Use WCF to encapsulate your external system. BDC supports &amp;#8220;basichttpbinding&amp;#8221; only. The following is a sample web.config. Here is one of the biggest catch. If running the WCF inside VS2008, use &amp;#8220;NTLM&amp;#8221;. After deploying the WCF to production, use &amp;#8220;Windows&amp;#8221;. It appears that VS2008 debug web server has different behavior in terms of WCF authentication. Also, in VS2008, you cannot test WCF authorization through [PrincipalPermission(SecurityAction.Demand, Name = &amp;#8220;&amp;#8221;)], it won&amp;#8217;t work.&lt;/h5&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt; &lt;span class="attr"&gt;behaviorConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;WindowsAuthorizationBehavior&amp;quot;&lt;/span&gt;
         &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;BDCContractImplementation&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt;   &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; 
                &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;basicHttpBinding&amp;quot;&lt;/span&gt; 
                &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;WindowsAuthenticationBinding&amp;quot;&lt;/span&gt;
     &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;IBDCContract&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;identity&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;dns&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;host&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
     &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;identity&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;behaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceBehaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;behavior&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;WindowsAuthorizationBehavior&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
             &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceMetadata&lt;/span&gt; &lt;span class="attr"&gt;httpGetEnabled&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
             &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceDebug&lt;/span&gt; &lt;span class="attr"&gt;includeExceptionDetailInFaults&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
             &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceCredentials&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;windowsAuthentication&lt;/span&gt; &lt;span class="attr"&gt;includeWindowsGroups&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;allowAnonymousLogons&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
             &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;serviceCredentials&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
             &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceAuthorization&lt;/span&gt; &lt;span class="attr"&gt;principalPermissionMode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;UseWindowsGroups&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;impersonateCallerForAllOperations&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;behavior&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;serviceBehaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;behaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;basicHttpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;WindowsAuthenticationBinding&amp;quot;&lt;/span&gt; 
                 &lt;span class="attr"&gt;maxBufferSize&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;2147483647&amp;quot;&lt;/span&gt;
                 &lt;span class="attr"&gt;maxReceivedMessageSize&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;2147483647&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt; &lt;span class="attr"&gt;mode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;TransportCredentialOnly&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;transport&lt;/span&gt; &lt;span class="attr"&gt;clientCredentialType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Ntlm&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="rem"&gt;&amp;lt;!-- works in VS2008 debug --&amp;gt;&lt;/span&gt;
            &lt;span class="rem"&gt;&amp;lt;!--&amp;lt;transport clientCredentialType=&amp;quot;Windows&amp;quot; /&amp;gt; --&amp;gt;&lt;/span&gt; &lt;span class="rem"&gt;&amp;lt;!-- works after deploying to IIS --&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;basicHttpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;ul&gt;
  &lt;h6&gt;&lt;/h6&gt;

  &lt;ul&gt;&lt;/ul&gt;

  &lt;li&gt;
    &lt;h5&gt;The catch of the return value from IDEnumerator in BDC. If the ID is of type string, you can not return list&amp;lt;string&amp;gt; from IDEnumerator. You must implement a simple class to encapsulate the ID; otherwise, for some reason, Microsoft Application Definition Designer won&amp;#8217;t able to handle the method&lt;/h5&gt;

    &lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;/* The small class to encapsulate the string */&lt;/span&gt;
[DataContract]
 &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MeetingID
 {
        [DataMember]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; MeetingIDStr { get; set; }
 }
[ServiceContract]
 &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IMeetingBDC
 {
        [OperationContract]
        List&amp;lt;Meeting&amp;gt; GetAllMeetings(&lt;span class="kwrd"&gt;string&lt;/span&gt; filter);
        [OperationContract]
        Meeting GetMeetingSpecificFinder(&lt;span class="kwrd"&gt;string&lt;/span&gt; meetingId);
        [OperationContract] &lt;span class="rem"&gt;/* the signature for IDEnumerator */&lt;/span&gt;
        List&amp;lt;MeetingID&amp;gt; GetMeetingIdEnumerator();
 }&lt;/pre&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;&lt;/h6&gt;

&lt;ul&gt;&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

  &lt;li&gt;
    &lt;h5&gt;BDC configuration using SSO. Copy paste and modify the following code:&lt;/h5&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;LobSystemInstance&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;BDCMeeting_Instance&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Properties&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;LobSystemName&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.String&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;LobMeeting&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;WebServiceAuthenticationMode&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Microsoft.Office.Server.ApplicationRegistry.SystemSpecific.WebService.HttpAuthenticationMode&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;WindowsCredentials&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;SsoProviderImplementation&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.String&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Microsoft.SharePoint.Portal.SingleSignon.SpsSsoProvider, Microsoft.SharePoint.Portal.SingleSignon, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;WebServiceSsoApplicationId&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.String&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;your_sso_application_id&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Properties&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;LobSystemInstance&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-8886743894361413238?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2010/02/access-external-data-in-sharepoint-with.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_ElXg_EOWn5c/S4VpHnYh-TI/AAAAAAAAAgY/kurQEtad0hs/s72-c/image_thumb2.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-5061497504069868901</guid><pubDate>Mon, 17 Aug 2009 14:41:00 +0000</pubDate><atom:updated>2009-08-18T05:33:30.557-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>SharePoint Analysis and Design Tips.</title><description>Object-Oriented Analysis and Design is a relatively mature technique. We call it Object-Oriented because the technique is to implement various requirements with objects in code. Likewise, In SharePoint Analysis and Design, we map requirements to SharePoint components such as web parts, lists, document libraries, views, site columns, content types, page layouts, info path forms, application pages, excel services, business catalogs, user profiles, my sites, site maps and so on. &lt;br /&gt;
The article is not to establish a methodology. It tries to explain a couple of experiences that may help in SharePoint Analysis and Design.&lt;br /&gt;
&lt;b&gt;1. &lt;/b&gt;&lt;b&gt;Map business requirements to technical solution as early as possible. &lt;/b&gt;&lt;br /&gt;
In object-oriented design, separating business domain requirements and technical solutions is a good practice. Technical solutions should not impact collecting business requirements if possible. However, this separation of requirement and solution is what SharePoint Analysis and Design should avoid. Considering technical solution at early stage will provide the following benefits:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Make business users aware what cannot be done with SharePoint's out-of-box features.&lt;/strong&gt; Business users expect SharePoint to do Anything through configuration, but custom development is inevitable for most of the enterprise-level MOSS applications. Custom development demands more efforts, and we need to inform those efforts to customers as early as possible. &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Give SharePoint developers the opportunities to explain the out-of-box features that will meet or exceed the same business goals with different business processes.&lt;/strong&gt; For example, the business goal of sharing knowledge and experience among employees can be archived by using out-of-box wiki library. Therefore, the original use cases collected from customers for achieving the same business goal will be altered according to the wiki libraries' behavior.&lt;/li&gt;
&lt;/ul&gt;2. &lt;b&gt;Strive for configurable/customizable solutions&lt;/b&gt;.&lt;br /&gt;
SharePoint allows end users to customize solutions without going through development cycles. End users may customize lists, document libraries, site pages, site master pages, define security groups and permission levels, etc; They may publish InfoPath forms and excel sheets, and create ad-hoc reports and dashboards using PerformancePoint. To take advantage of those features while designing SharePoint solution, consider separate the responsibilities of developers and end users. Both end users and developers have the responsibilities to contribute to SharePoint solutions. For example, in an InfoPath form, developers implement the web services for InfoPath to connect to and configure the SSO application while end users are responsible to create the InfoPath connections to the web services using SSO authentication. The relationship between developers and end users is very much like how frameworks' developers are related to the developers who use the frameworks. Basically, developers should deal with more difficult tasks and expose their work through interfaces to end users. The interfaces in SharePoint context, which is very different from the .NET interfaces, are in the formats of InfoPath connection, SSO, Content Type, Page Layout, etc.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-5061497504069868901?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/08/sharepoint-analysis-and-design.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-1506076511286110878</guid><pubDate>Sun, 09 Aug 2009 21:24:00 +0000</pubDate><atom:updated>2009-08-20T09:38:01.221-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>SharePoint Workflow - Use IListItemService to manipulate list items other than the workflow list items.</title><description>&lt;p&gt;SharePoint workflows can use OnWorkflowItemChanged and OnWorkflowItemDeleted activities to capture the &amp;quot;changed&amp;quot; and &amp;quot;deleted&amp;quot; events for the list items associated with the SharePoint workflow instances. To capture the &amp;quot;changed&amp;quot; and &amp;quot;deleted&amp;quot; events for the list items &lt;i&gt;&lt;strong&gt;not &lt;/strong&gt;associated&lt;/i&gt; with SharePoint workflow instances, we need to use SharePoint workflows' IListItemService.&lt;/p&gt;  &lt;p&gt;IListItemService is one of four ExternalDataExchange services - IListItemService, ISharPointService, ITaskService and IWorkflowModificationService - registered by SharePoint runtime. IListItemService provides the methods and events to handle any list items in the SharePoint Site Collection where a workflow instance is running. To study the interface, I developed two workflows to illustrate two different scenarios using IListItemService.&lt;/p&gt;  &lt;h4&gt;&lt;b&gt;Scenario 1:&lt;/b&gt; A workflow needs to capture the OnItemChanged event of a pre-existing list item. &lt;/h4&gt;  &lt;p&gt;To test the scenario, I created two SharePoint lists: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;workflowlist&lt;/b&gt;: it has a workflow association with the testing workflow and one item called &amp;quot;workflow item&amp;quot;. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;anotherlist&lt;/b&gt;: the changed events of its items should be captured by the testing workflow associated with workflowlist above. The list's listid is 7c455073-56ce-4ecd-bfa8-2923fc521b9e and it has one item called &amp;quot;another list item&amp;quot;. The id of the item is 1. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The following is the design view of the testing workflow:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/SoxkzdCMxQI/AAAAAAAAAYA/jTpxAugNsG8/s1600-h/clip_image002%5B5%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Soxkz91NcGI/AAAAAAAAAYE/1ZEwQ6rn33g/clip_image002_thumb%5B2%5D.jpg?imgmax=800" width="360" height="241" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The workflow includes three activities:&lt;/p&gt;  &lt;p&gt;1. OnWorkflowActivated activity is required by all the SharePoint workflows. &lt;/p&gt;  &lt;p&gt;2. InvokeIntializeForEvent is a subclass of CallExternalMethodActivity with the following parameters:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/Soxk0GzFA2I/AAAAAAAAAYI/YOCBsHh65C4/s1600-h/clip_image004%5B6%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://lh4.ggpht.com/_ElXg_EOWn5c/Soxk0jw953I/AAAAAAAAAYM/6h-lWqv8QJo/clip_image004_thumb%5B3%5D.jpg?imgmax=800" width="462" height="319" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The activity will invoke the InitializeForEvent method defined in the IListItemService interface. The signature of the method is:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[CorrelationParameter(&lt;span style="color: #006080"&gt;&amp;quot;id&amp;quot;&lt;/span&gt;), CorrelationParameter(&lt;span style="color: #006080"&gt;&amp;quot;itemId&amp;quot;&lt;/span&gt;), CorrelationParameter(&lt;span style="color: #006080"&gt;&amp;quot;listId&amp;quot;&lt;/span&gt;), ExternalDataExchange, SharePointPermission(SecurityAction.LinkDemand, ObjectModel=&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;), SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel=&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)]&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IListItemService&lt;br /&gt;{&lt;br /&gt;    ......&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; InitializeForEvent(Guid id, Guid listId, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; itemId);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;&lt;/div&gt;

&lt;p&gt;
  &lt;table border="0" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" width="678"&gt;
          &lt;p&gt;
            &lt;table border="1" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td valign="top" width="108"&gt;
                    &lt;p&gt;Parameter Name&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="342"&gt;
                    &lt;p&gt;Parameter Value&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="225"&gt;
                    &lt;p&gt;Description&lt;/p&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;

                &lt;tr&gt;
                  &lt;td valign="top" width="108"&gt;
                    &lt;p&gt;id&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="342"&gt;
                    &lt;p&gt;f1bb0cd5-e470-4e70-90ea-e37525a3662a&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="225"&gt;
                    &lt;p&gt;A GUID generated at development time&lt;/p&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;

                &lt;tr&gt;
                  &lt;td valign="top" width="108"&gt;
                    &lt;p&gt;itemId&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="342"&gt;
                    &lt;p&gt;1&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="225"&gt;
                    &lt;p&gt;The id for the “another list item” list item&amp;#160; in the &amp;quot;anotherlist&amp;quot; SharePoint list &lt;/p&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;

                &lt;tr&gt;
                  &lt;td valign="top" width="108"&gt;
                    &lt;p&gt;listId&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="342"&gt;
                    &lt;p&gt;7c455073-56ce-4ecd-bfa8-2923fc521b9e&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="225"&gt;
                    &lt;p&gt;The id of the &amp;quot;anotherlist&amp;quot; SharePoint list&lt;/p&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;&lt;/table&gt;
          &lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/p&gt;

&lt;p&gt;3. handeItemChangedEvent is a HandleExternalEvent activity with the following parameters:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/Soxk1bidPYI/AAAAAAAAAYQ/N2UtuYnqQuA/s1600-h/clip_image006%5B5%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://lh4.ggpht.com/_ElXg_EOWn5c/Soxk1x88sHI/AAAAAAAAAYU/PtiCF49jDLA/clip_image006_thumb%5B2%5D.jpg?imgmax=800" width="448" height="307" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This activity will wait on the OnItemChanged event defined in IListItemService interface. It should use the same Correlation Token, newtoken, for the activity prior to it. &lt;/p&gt;

&lt;p&gt;We can test the workflow with the following steps:&lt;/p&gt;

&lt;p&gt;1. Start the workflow for the &amp;quot;workflow item” list item in the &amp;quot;workflowlist&amp;quot; SharePoint list. The workflow should stop at &amp;quot;in progress&amp;quot; status since it is blocked and waiting for the OnItemChanged event.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/Soxk2P1WUGI/AAAAAAAAAYY/sZenqJvkeTQ/s1600-h/clip_image008%5B6%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://lh6.ggpht.com/_ElXg_EOWn5c/Soxk2jSjEvI/AAAAAAAAAYc/-Vr8y0QGm0E/clip_image008_thumb%5B3%5D.jpg?imgmax=800" width="447" height="171" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2. Modify the &amp;quot;another list item&amp;quot; list item in the &amp;quot;anotherlist&amp;quot; list and change its title to &amp;quot;another list item changed&amp;quot;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/Soxk3Rxx1jI/AAAAAAAAAYg/ZgUX-F_eCPc/s1600-h/clip_image010%5B7%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Soxk34LR1eI/AAAAAAAAAYk/_BzH-_d3uyQ/clip_image010_thumb%5B4%5D.jpg?imgmax=800" width="488" height="246" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3. Go back to the workflow list. Its workflow status is changed to complete since step 2 modifies the list item and trigger OnItemChanged event.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh5.ggpht.com/_ElXg_EOWn5c/Soxk4ISsfyI/AAAAAAAAAYo/3p7ba2XQQyw/s1600-h/image%5B8%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Soxk4iKaqlI/AAAAAAAAAYs/GptqVTObZOY/image_thumb%5B6%5D.png?imgmax=800" width="514" height="291" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The solution demonstrates the following key points:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;IListItemService.InitializeForEvent should be invoked to establish the correlation token for a list item before you can capture the event for the list item. (You may use IListItemService.UpdateListItem, CheckInListItem, etc instead. ). &lt;/li&gt;

  &lt;li&gt;listId and itemId for InitializeForEvent must match the ids of the SharePoint list and list item. &lt;/li&gt;

  &lt;li&gt;id for InitalizeForEvent can be any uniquely generated GUID. It does not need to match any ids. &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;&lt;b&gt;Scenario 2&lt;/b&gt;: A workflow needs to create an new list item and wait on its changed events. &lt;/h4&gt;

&lt;p&gt;In this case, you need to use IListItemSevice.CreateListItem to create the list. However, you cannot use the correlation token for CreateListItem because the &amp;quot;itemId&amp;quot; parameter is unknown while invoking the method.&amp;#160; You can get the itemId as a &amp;quot;returnvalue&amp;quot; in your workflow instead.&lt;/p&gt;

&lt;p&gt;So, here is the solution:&lt;/p&gt;

&lt;p&gt;1. Add a CallExternalMethod activity to invoke the &amp;quot;CreateListItem&amp;quot; method. The activity should include an event handler for MethodInvokded event. In the event handler, get the return value and assign the value to a member variable to the workflow.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnMethodInvoked(EventArgs e)&lt;br /&gt;{&lt;br /&gt;   &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ItemId = (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)&lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.ParameterBindings[&lt;span style="color: #006080"&gt;&amp;quot;(ReturnValue)&amp;quot;&lt;/span&gt;].Value;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;&lt;/div&gt;

&lt;p&gt;2. Add an InitializeForEevnt activity to invoke the &amp;quot;InitializeForEvent&amp;quot; method. Make sure use the ItemId returned by CreateListItem. This activity should create a new token, which is different from the one for &amp;quot;CreateListItem&amp;quot;. The token for &amp;quot;CreateListItem&amp;quot; is basically not used any where.&lt;/p&gt;

&lt;p&gt;3. Add an HandleExteranlEvent activity as in Scenario 1. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-1506076511286110878?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/08/sharepoint-workflow-use.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_ElXg_EOWn5c/Soxkz91NcGI/AAAAAAAAAYE/1ZEwQ6rn33g/s72-c/clip_image002_thumb%5B2%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-4034902227563904808</guid><pubDate>Fri, 31 Jul 2009 20:02:00 +0000</pubDate><atom:updated>2009-08-14T20:04:26.862-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>Why are we getting "(1385) System.ComponentModel.Win32Exception: Logon failure: the user has not been granted the requested logon type at this computer"</title><description>SharePoint InfoPath Service can use SSO to access external resources such as web services and SQL server databases.&amp;#160; &lt;br /&gt; As explained at &lt;a title="http://blogs.msdn.com/infopath/archive/2006/06/27/advanced-server-side-authentication-for-data-connections-part-2.aspx" href="http://blogs.msdn.com/infopath/archive/2006/06/27/advanced-server-side-authentication-for-data-connections-part-2.aspx" target="_blank"&gt;MSDN site&lt;/a&gt;,&amp;#160; an InfoPath form can access external data sources through connection files. Behind the scene, the InfoPath runtime will get the credential to impersonate through SSO API and invoke LogOnUser function with the credential if Windows authentication is used.&amp;#160; &lt;br /&gt;You may run into the following exception while running an InfoPath form with SSO connections:  &lt;br /&gt;&lt;strong&gt;LogonUser failed for user 'domain\username' (1385) System.ComponentModel.Win32Exception: Logon failure: the user has not been granted the requested logon type at this computer&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/strong&gt;  &lt;br /&gt;If you Google&amp;#160; the exception for solution, you may find the advice to&amp;#160; give the delegated user “Allow Log on locally”&amp;#160; windows right. But, it won’t help. Even if you add the user to the local administrator group, it still doesn’t work. To solve this issue, we need to understand how InfoPath Service runtime impersonates with the credential configured in SSO. Writing a web part using SSO API and LogOnUser will help us to understand what is happening inside the InfoPath runtime.&amp;#160; &lt;br /&gt;The following code segment explains the three steps to use SSO in a web part:   &lt;br /&gt;  &lt;ul&gt;   &lt;li&gt;Retrieve the credential used to connect to the external database through SSO API; &lt;/li&gt;    &lt;li&gt;Impersonate the credential using LogonUser; &lt;/li&gt;    &lt;li&gt;Create a ADO connection to the database using Integrated Security;&amp;#160; &lt;/li&gt; &lt;/ul&gt;  &lt;div&gt;   &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: green"&gt;//*******************************************************************&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: green"&gt;//Step 1: Get the account for connecting to database from SSO API&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;[] strCredentialData = &lt;span style="color: blue"&gt;null&lt;/span&gt;;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: green"&gt;//Credentials.Get Credentials is a SharePoint SSO API&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;Credentials.GetCredentials(1, &lt;span style="color: #006080"&gt;&amp;quot;eex&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;ref&lt;/span&gt; strCredentialData);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt; strUserName = strCredentialData[0];&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;[] domainUserName = strUserName.Split('\\');&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt; strPassword = strCredentialData[1];&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: green"&gt;//***********************************************************************&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: green"&gt;//Step 2: Use LogOnUser to impersonate with the account&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;bool&lt;/span&gt; result = LogonUser(domainUserName[1], domainUserName[0],&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;strPassword,&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;LogonSessionType.Batch,&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;LogonProvider.Default,&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;out&lt;/span&gt; token);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;WindowsIdentity id = &lt;span style="color: blue"&gt;new&lt;/span&gt; WindowsIdentity(token);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;impersonatedUser = id.Impersonate();&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: green"&gt;//************************************************************************&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: green"&gt;//Step 3:Use ADO.NET with Integrated Security to retrieve data from the external database.&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt; resultFromDb = &lt;span style="color: blue"&gt;null&lt;/span&gt;;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; (SqlConnection connection = &lt;span style="color: blue"&gt;new&lt;/span&gt; SqlConnection(&lt;span style="color: #006080"&gt;&amp;quot;Integrated Security=SSPI;Initial Catalog=external_test;Data Source=sqlserver&amp;quot;&lt;/span&gt;))&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;connection.Open();&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;SqlCommand command = &lt;span style="color: blue"&gt;new&lt;/span&gt; SqlCommand(&lt;span style="color: #006080"&gt;&amp;quot;select * from simple&amp;quot;&lt;/span&gt;, connection);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; (SqlDataReader reader = command.ExecuteReader())&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;reader.Read();&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;resultFromDb = (&lt;span style="color: blue"&gt;string&lt;/span&gt;)reader[0];&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;}&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;connection.Close();&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;}&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
The code above explains how, behind the scene, SharePoint Form Service is using LogOnUser to impersonate an account. So the reason we got the &amp;quot;LogonUser failed for user 'domain\username' (1385) System.ComponentModel.Win32Exception: Logon failure: the user has not been granted the requested logon type at this computer&amp;quot; is that SharePoint Form Service invokes LogonUser with &lt;strong&gt;Batch&lt;/strong&gt;&amp;#160; logon session type (the fourth parameter to LogonUser). Therefore, you need to configure the the security policy of your Web Front End to&amp;#160; give the delegated user “Log on as Batch” right. The following screen shot demonstrates the configuration.&amp;#160;&amp;#160; &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/SnNNtRb2ZfI/AAAAAAAAAWI/DZBp6d7s4KM/s1600-h/image%5B6%5D.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="159" alt="image" src="http://lh3.ggpht.com/_ElXg_EOWn5c/SnNNuAcXURI/AAAAAAAAAWM/T-P65Bb7zMc/image_thumb%5B4%5D.png?imgmax=800" width="734" border="0" /&gt;&lt;/a&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-4034902227563904808?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/07/infopath-service-single-sign-on.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_ElXg_EOWn5c/SnNNuAcXURI/AAAAAAAAAWM/T-P65Bb7zMc/s72-c/image_thumb%5B4%5D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-8382629138778399161</guid><pubDate>Thu, 23 Jul 2009 21:14:00 +0000</pubDate><atom:updated>2009-07-24T09:00:36.480-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>Understand MOSS Search Run Time Architecture</title><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Understanding SharePoint Search Run Time Architecture is very helpful in planning/configuring SharePoint farm and troubleshooting Kerberos authentication. I recently read the following paragraph from &lt;a href="http://technet.microsoft.com/en-us/library/cc263044.aspx"&gt;Microsoft Web Site&lt;/a&gt; regarding SharePoint search planning:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;In Office SharePoint Server 2007, the index role is associated with a Shared Services Provider (SSP). The index role builds one index per SSP. One index server can be associated with multiple SSPs. However, indexes across SSPs cannot be combined. You can deploy multiple index servers to improve capacity. In this case, each index server is associated with different SSPs. Unlike the Windows SharePoint Services 3.0 search role, content indexes produced by the Office SharePoint Server 2007 index role are continuously propagated to all servers that host the query role in a farm. Consequently, the output of the Office SharePoint Server 2007 index server role (that is, the index) is considered redundant if the query role is deployed to more than one server computer.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Let me explain this in detail.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;What are index role, query role, index server and query server?&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Index role&lt;/strong&gt; is a logic role or responsibility that crawls contents and build index files. &lt;strong&gt;Query role&lt;/strong&gt; is a logic role or responsibility that returns query results. &lt;strong&gt;Index Server/Query Server&lt;/strong&gt; is an &lt;b&gt;Office SharePoint Server Search&lt;/b&gt; Windows Service instance running on a server in the SharePoint Farm. The following picture shows the Services Console of a SharePoint Server:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_ElXg_EOWn5c/SmjSvrkhHII/AAAAAAAAAUg/oGKX71vRdHs/s1600-h/clip_image002%5B6%5D.jpg"&gt;&lt;img title="clip_image002" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="78" alt="clip_image002" src="http://lh6.ggpht.com/_ElXg_EOWn5c/SmjSvw0eZ5I/AAAAAAAAAUk/Irdh7AHWCcI/clip_image002_thumb%5B3%5D.jpg?imgmax=800" width="709" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;An Office SharePoint Server Search&lt;/b&gt; Windows Service Instance can be configured to run as an index role, a query role or both. If an instance of MOSS Windows Search Service is configured as Index role. It is called Index Server. The same applies to the Search Role. &lt;/p&gt;  &lt;p&gt;To start and configure a Index or Search server, open SharePoint Central Administration. Click the operation tab and then click &amp;quot;Services on the Server&amp;quot;, the following window displays:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/SmjSwf-cKjI/AAAAAAAAAUo/8Ka86A1RgKU/s1600-h/clip_image004%5B6%5D.jpg"&gt;&lt;img title="clip_image004" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="326" alt="clip_image004" src="http://lh4.ggpht.com/_ElXg_EOWn5c/SmjSwvsNANI/AAAAAAAAAUs/BYvLZGY5YGc/clip_image004_thumb%5B3%5D.jpg?imgmax=800" width="790" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Click the &amp;quot;Office SharePoint Server Search&amp;quot; link. The screen to configure the Server Role for the Office SharePoint Server Search displays:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_ElXg_EOWn5c/SmjSxEUkguI/AAAAAAAAAUw/rPs53QYWl9k/s1600-h/clip_image006%5B5%5D.jpg"&gt;&lt;img title="clip_image006" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="329" alt="clip_image006" src="http://lh5.ggpht.com/_ElXg_EOWn5c/SmjSxnKOzdI/AAAAAAAAAU0/ZZFnPXIiQZU/clip_image006_thumb%5B2%5D.jpg?imgmax=800" width="650" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In this page, you can determine what roles the instance of &lt;b&gt;Office SharePoint Server &lt;/b&gt;will play by selecting the check boxes at the top of the page.&lt;/p&gt;  &lt;p&gt;We know how to create Index and Search server for a SharePoint farm. In a SharePoint Farm, we can have multiple SSPs. Each SSP may have different contents to search. The question is which SSP the index and Search server will work for. To answer the question, we need to study another setting. While creating a SSP, you will be ask to choose an index server:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/SmjSx1kKFII/AAAAAAAAAU4/H77L6tveRq8/s1600-h/clip_image008%5B5%5D.jpg"&gt;&lt;img title="clip_image008" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="236" alt="clip_image008" src="http://lh4.ggpht.com/_ElXg_EOWn5c/SmjSySrSI3I/AAAAAAAAAU8/mJWSyy3uyiQ/clip_image008_thumb%5B2%5D.jpg?imgmax=800" width="551" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The &amp;quot;Index Server&amp;quot; drop down list will allow you to choose which index server to use for the SSP. However, there is no selection for a Search Server. Therefore, we know:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;A SSP can have one and only one index server.&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;A Search Server will serve for all the SSPs created in the farm.&lt;/strong&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Now, let us re-visit the paragraph from Microsoft Web Site using the knowledge we just learned:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;In Office SharePoint Server 2007, the index role is associated with a Shared Services Provider (SSP). The index role builds one index per SSP. One index server can be associated with multiple SSPs. However, indexes across SSPs cannot be combined. You can deploy multiple index servers to improve capacity. In this case, each index server is associated with different SSPs.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;It is in line with &amp;quot;A SSP can have one and only one index server&amp;quot;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Unlike the Windows SharePoint Services 3.0 search role, content indexes produced by the Office SharePoint Server 2007 index role are continuously propagated to all servers that host the query role in a farm. &lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;It is in line with &amp;quot;A Search Server will serve all the SSPs created in the farm&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Consequently, the output of the Office SharePoint Server 2007 index server role (that is, the index) is considered redundant if the query role is deployed to more than one server computer.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;It basically says that you can scale out for Search Server. However, you cannot scale out for Index Server inside one instance of SSP. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-8382629138778399161?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/07/understand-moss-search-run-time.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_ElXg_EOWn5c/SmjSvw0eZ5I/AAAAAAAAAUk/Irdh7AHWCcI/s72-c/clip_image002_thumb%5B3%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-3927883542614915375</guid><pubDate>Sat, 18 Jul 2009 13:39:00 +0000</pubDate><atom:updated>2009-07-24T12:27:41.481-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>Interesting observation on SharePoint Security</title><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The article lists some SharePoint Security related facts/experience that may be helpful. Please add your comments if you think the list should expand&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Anonymous Users can add/edit/delete list items. However, they can never add/edit/delete document library items even though they can view document library items. &lt;/li&gt;    &lt;li&gt;It is not possible to make some of the items in a list/document library accessible to anonymous users while other items not accessible. All the items in a list/document library must have the same accessibility for anonymous users. &lt;/li&gt;    &lt;li&gt;You cannot add a Windows Group to Site Collection Administrators. You can only add individual users. It is by design. In my opinion, however, it is not convenient for administration.&lt;/li&gt;    &lt;li&gt;A common misconception is that a user in the Site Owner group can access all the contents in a site. In theory, you must check item level permission for all the items in all the lists to make sure a user can access all the contents in a site. To be complete, you need also to check the Security Policy for the web application. Never assume a site owner can do anything.&lt;/li&gt;    &lt;li&gt;Limited Access Permission Level is to be added by SharePoint automatically. For example, assuming a user does not have any permission in a SharePoint site, if you add an item level read permission to the user for an item of a list. The SharePoint will add Limited Access Permission Level to the user at the list and the site level automatically. &lt;/li&gt;    &lt;li&gt;SharePoint does not have the finest permission granularity. For example, it is not possible to have one user to have edit site title and image permission and the other to have delete child sub sites permission. This is because &amp;quot;Manage Web Site&amp;quot; permission includes both edit site title/image and delete child sub sites. This lack of finest permission does cause problem in practice since you have to assign the same people to perform two very different categories of administrative tasks.&lt;/li&gt;    &lt;li&gt;...... more to come&lt;/li&gt; &lt;/ol&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-3927883542614915375?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/07/interesting-observation-on-sharepoint.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-3140411727173915446</guid><pubDate>Fri, 17 Jul 2009 03:00:00 +0000</pubDate><atom:updated>2009-08-14T19:56:12.160-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>SharePoint Security for the contents in _layouts, _controltemplates and _vti_bin directories in the context of SharePoint NTLM authentication</title><description>&lt;p&gt;A SharePoint web application can be accessed through multiple IIS web sites with different authentication such as NTLM, Kerberos and Form. It is important to differentiate a SharePoint Web Application and the IIS Web Sites accessing the SharePoint Web Application. Typically, each IIS Web Site accessing a SharePoint Web Application will correspond to a zone in SharePoint's Alternate Access Mapping. Each zone has a public address and multiple internal addresses. The multiple internal addresses typically map to addresses for load balancing. &lt;/p&gt;  &lt;p&gt;The article discusses the authorization on accessing the files in _layouts (application pages and resources), _controltemplates (user controls and resources) , _vti_bin ( web services) in the context of an IIS Web Site or Zone configured with NTLM authentication.&lt;/p&gt;  &lt;p&gt;If an IIS Web Site to access a SharePoint Web application is configured with NTLM authentication, the authorization to the contents in those directories is mostly determined by ASP.NET 2.0 Windows authentication mechanism. &lt;/p&gt;  &lt;p&gt;When a SharePoint IIS web site is configured with NTLM authentication, the web.config file of the web site has &amp;quot;Windows&amp;quot; as its authentication method. In Windows authentication, Asp.NET 2.0 actually relies on IIS to perform authentication (basic, digest and integrated). The IIS will produce a security token after the authentication and then pass the security token to ASP.NET. Then, ASP.NET will perform two types of authorization using the identity encapsulated in the security token.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;URL authorization (You can edit the web.config files in _layouts, _controltemplates and _vti_bin to define URL authorization)&lt;/li&gt;    &lt;li&gt;ACL authorization. This authorization does not occur for Form authentication.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;It is important to realize both authorizations will apply. Therefore, even if a user has URL authority to access an ASPX or image file, he/she may still not be able to access them due to the failure of ACL authorization.&lt;/p&gt;  &lt;p&gt;Notice, the &amp;quot;impersonate&amp;quot; will not affect the above process. It will only affect when you write server side code, for example, when you try to open a local file in your web part. SharePoint always has &amp;quot;impersonate&amp;quot; as true.&lt;/p&gt;  &lt;p&gt;In SharePoint NTLM (not Form) authentication, accessing the files and resources in _layouts, _controltemplates and _vti_bin pretty much follows the two authorization methods (URL and ACL) of ASP.NET 2.0. However, there is just one exception to the rule. For ASPX pages in the layouts directory that inherits from out-of-box class Microsoft.SharePoint.WebContorls.LayoutsPageBase, the class will check if the current SharePoint user has &amp;quot;View Application Pages&amp;quot; permission. So, it is the third authorization methods applied to those pages.&lt;/p&gt;  &lt;p&gt;Now add anonymous users to the mix. Like authenticated users, the authorization for anonymous users is pretty much determined by ASP.NET 2.0 with one exception that is the pages inheriting from Microsoft.SharePoint.WebContorls.LayoutsPageBase. There are some interesting things worth metioning:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;URL authorization will use question mark &amp;quot;?&amp;quot; to denote anonymous users;&lt;/li&gt;    &lt;li&gt;ACL authorization will use IUSR_MachineName account. (This account is configurable in IIS);&lt;/li&gt;    &lt;li&gt;Anonymous users can never load pages inheriting from Microsoft.SharePoint.WebContorls.LayoutsPageBase;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The first two are just typical ASP.NET 2.0 way of handling security. The third one is really a surprise. SharePoint anonymous users by default should have &amp;quot;limited access&amp;quot; permission level that should have &amp;quot;View Application Pages&amp;quot; permission. However, anonymous users still cannot access the pages inheriting from Microsoft.SharePoint.WebContorls.LayoutsPageBase even with the &amp;quot;View Application Page&amp;quot; permission. I could not explain why and just remember that this as an exceptional scenario. To expose SharePoint Application Page to anonymous users, do not use Microsoft.SharePoint.WebContorls.LayoutsPageBase as its base page class.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-3140411727173915446?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/07/sharepoint-security-for-contents-in.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-2133392215358143008</guid><pubDate>Thu, 02 Apr 2009 23:40:00 +0000</pubDate><atom:updated>2009-04-28T19:19:41.581-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>Inside SharePoint SafeControl</title><description>&lt;p&gt;I saw quite a few times that while seeing security exception thrown from SharePoint, the first reaction is to add a SafeControl entry. SharePoint will tell you very clearly if you need to add any SafeControl entry in your Web.Config. Typically, you should see the error message similar to the following:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;Parser Error &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;Parser Error Message: The control type 'Dummy.DummyUnsafeWebPart' is not allowed on this page. The type is not registered as safe.&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;If you have not seen the message, do not try to add any SafeControl. SafeControl is a SharePoint-special security mechanism. A common MISTAKE is to assume a Dll will have full trust&amp;#160; if the Dll is added to the SafeControl list. &lt;/p&gt;

&lt;p&gt;The SafeContol entries are checked by SharePoint parser to make sure Controls are &amp;#8220;safe&amp;#8221; to be placed in a page declaratively. It is important to know that only SharePoint Parser honors SafeControl. After parsing stage,&amp;#160; SafeControl is out of Picture. This can be explained by the following sample code:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;[ToolboxData(&amp;quot;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;{0}:DummySPWebPart runat=server&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;{0}:DummySPWebPart&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&amp;quot;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;public class DummySafeWebPart : WebPart&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    protected override void CreateChildControls()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        this.Controls.Clear();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        this.Controls.Add(new Dummy.DummyUnsafeWebPart());&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;[ToolboxData(&amp;quot;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;{0}:DummyWebPart runat=server&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;{0}:DummyWebPart&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&amp;quot;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;public class DummyUnsafeWebPart : WebPart&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    protected override void RenderContents(HtmlTextWriter output)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        output.Write(&amp;quot;Hello World&amp;quot;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;&amp;#160;&lt;/div&gt;

&lt;p&gt;The code shows the implementation of two web parts, DummySafeWebPart and DummyUnsafeWebPart. DummySafeWebPart just creates and adds an DummyUnsafeWebPart to its Children&amp;#8217;s collection. Add an SafeControl entry to Web.Config for DummySafeWebPart. Now, testing the following two scenarios:&lt;/p&gt;

&lt;p&gt;Scenario 1: A sharepoint page containing DummySafeWebPart only&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Register assembly=&amp;quot;SPDummy&amp;quot; namespace=&amp;quot;SPDummy&amp;quot; tagprefix=&amp;quot;SPDummy&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt; &lt;span style="color: #ff0000"&gt;dir&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ltr&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;META&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;WebPartPageExpansion&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;content&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;full&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;META&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;WebPartPageExpansion&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;content&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;full&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;form1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SPDummy:DummySafeWebPart&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Open the page in a Brower, it works fine.&lt;/p&gt;

&lt;p&gt;Scenario 2. A sharepoint page containing DummyUnsafeWebpart only:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Register assembly=&amp;quot;Dummy&amp;quot; namespace=&amp;quot;Dummy&amp;quot; tagprefix=&amp;quot;Dummy&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt; &lt;span style="color: #ff0000"&gt;dir&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ltr&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;META&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;WebPartPageExpansion&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;content&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;full&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;META&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;WebPartPageExpansion&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;content&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;full&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;form1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Dummy:DummyUnsafeWebPart&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;  &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Open the page in a Brower,&amp;#160; it throws exception:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh5.ggpht.com/_ElXg_EOWn5c/SdVM1QzKu5I/AAAAAAAAAUA/S0g8Rg_-LXw/s1600-h/image%5B2%5D.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="64" alt="image" src="http://lh4.ggpht.com/_ElXg_EOWn5c/SdVM142jkjI/AAAAAAAAAUE/aA7fMEQhygE/image_thumb.png?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The two testing scenarios show that an &amp;#8220;unsafe&amp;#8221; control can be loaded by a &amp;#8220;safe&amp;#8221; control in sharepoint. However, if you place the &amp;#8220;unsafe&amp;#8221; control declaratively in a sharepoint content page, sharepoint will complain. This is becanse SharePoint Parser can not see the loading of unsafe control inside safecontrol. Parser can only see whatever controls your place &lt;strong&gt;declaratively&lt;/strong&gt; in a page. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-2133392215358143008?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/04/inside-sharepoint-safecontrol.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_ElXg_EOWn5c/SdVM142jkjI/AAAAAAAAAUE/aA7fMEQhygE/s72-c/image_thumb.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-3871683526807230619</guid><pubDate>Sat, 28 Mar 2009 21:44:00 +0000</pubDate><atom:updated>2009-03-30T14:16:32.431-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>SharePoint, Trust Level and Code Access Security</title><description>&lt;p&gt;In Windows, there are two types of security mechanisms: Role based Security and Code Access Security. Role based security is easy to understand. Code Access Security(CAS) is to prevent &amp;#8220;Bad&amp;#8221; module from doing any damage. A&amp;#160; module is &amp;#8220;Bad&amp;#8221; if it does not just do what it claims to do. For example, you run a module downloaded from internet to display a nice screen saver. However, although the module displays the screen saver, it also silently sends your local files to a remote location. In this case, the module does not just do what supposed to do.    &lt;br /&gt;How does CAS prevent &amp;#8220;Bad&amp;#8221; module from doing any damage? It is achieve by two mechanisms working together.     &lt;br /&gt;1.&amp;#160;&amp;#160;&amp;#160; Configure CAS policy so the &amp;#8220;Bad&amp;#8221; module won&amp;#8217;t have the CAS permission to do damage such as sending files to a remote location.     &lt;br /&gt;2.&amp;#160;&amp;#160;&amp;#160; The code of sending file to a remote location must use CAS security Demand to demand the calling module to have the CAS permission. In case of sending files to a remote location. &amp;#8220;WebRequest&amp;#8221; CAS permission is demanded. Without the security demanding, configuring CAS policy is useless since CAS security enforcement typically starts with CAS permission demanding and then checks the security policy to see if the demanded permission is granted to the calling module.&amp;#160; &lt;br /&gt;While developing CAS strategy, in addition to configure CAS security policy, it is important to use the second mechanism so the code you wrote won&amp;#8217;t be used by &amp;#8220;Bad&amp;#8221; module to cause any damage. &lt;/p&gt;  &lt;p&gt;In SharePoint, it is a best practice to deploy your Dlls to the bin directory instead of GAC and configure minimum CAS permissions for the Dlls through CAS policy files. The tutorial will guide your through how to do it.&amp;#160; The tutorial will use a couple of&amp;#160; simple custom web parts, deploy them into the bin directory and use them in sharepoint content pages.&amp;#160; &lt;/p&gt;  &lt;p&gt;Lab 1: Deploy and use the first web part in SharePoint&lt;/p&gt;  &lt;p&gt;Step 1: Develop DummyWebPart, build a Dll (Dummy.dll), copy dummy.dll to the SharePoint&amp;#8217;s Bin directory&lt;/p&gt;  &lt;p&gt;The source code of the first web part &lt;strong&gt;DummyWebpart&lt;/strong&gt; is as the following&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;namespace Dummy&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    [ToolboxData(&amp;quot;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;{0}:DummyWebPart runat=server&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;{0}:DummyWebPart&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&amp;quot;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    public class DummyWebPart : WebPart&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        protected override void RenderContents(HtmlTextWriter output)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            output.Write(&amp;quot;Hello World&amp;quot;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;DummyWepart writes &amp;#8220;Hello World&amp;#8221;. That is it! &lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;Step 2: Do not forget adding the following SafeControl entry to your web.config since we are using DummyWebPart in a Customized Content Page.&amp;#160; It is important to know &amp;#8220;SafeControl&amp;#8221; has nothing to do with Code Access Security. It is something used by SharePoint Page Parser to forbid unregistered WebControl in a &lt;strong&gt;customized&lt;/strong&gt; &lt;strong&gt;content&lt;/strong&gt; page! &lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SafeControls&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     ......&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SafeControl&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Assembly&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Dummy&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Namespace&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Dummy&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;TypeName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;*&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Safe&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     ......&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;SafeControls&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;Step 3: Create a SharePoint Content Page Dummy.aspx to host the DummyWebPart. The source code of Dummy.aspx is as the following&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Register assembly=&amp;quot;Dummy&amp;quot; namespace=&amp;quot;Dummy&amp;quot; tagprefix=&amp;quot;Dummy&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt; &lt;span style="color: #ff0000"&gt;dir&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ltr&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;form1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Dummy:DummyWebPart&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;DummyWebPart1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Now, open Dummy.aspx in the SharePoint site in a browser. It just works without any trouble&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh5.ggpht.com/_ElXg_EOWn5c/Sc6aIj280CI/AAAAAAAAATo/z50z27kpMjU/s1600-h/image%5B2%5D.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="156" alt="image" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Sc6aJPhWapI/AAAAAAAAATs/zVwVlwV9e2E/image_thumb.png?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Lab 2: Deploy and use the second web part,DummySPWebPart, in SharePoint, which will cause Code Access Security Exception.&lt;/p&gt;

&lt;p&gt;Step 1: Develop DummySPWebPart, build a Dll (SPDummy.dll), copy the SPDummy.dll to Bin directory &lt;/p&gt;

&lt;p&gt;The source code of the second&amp;#160; web part&amp;#160; &lt;strong&gt;DummySPWepart&lt;/strong&gt; is as the following &lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;namespace SPDummy&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    [ToolboxData(&amp;quot;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;{0}:DummySPWebPart runat=server&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;{0}:DummySPWebPart&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&amp;quot;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    public class DummySPWebPart : WebPart&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;       &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        protected override void RenderContents(HtmlTextWriter output)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            output.Write(string.Format(&amp;quot;root web title is {0}&amp;quot;,SPContext.Current.Site.RootWeb.Title));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;DummySPWepart writes the Title of the SharePoint root web site. It invokes SPContent.Current.Site.RootWeb.Title in order to get the Tile. &lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;Step 2: Do not forget adding the following SafeControl entry to your web.config. &lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SafeControls&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     ......&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SafeControl&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Assembly&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SPDummy&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Namespace&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SpDummy&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;TypeName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;*&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Safe&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     ......&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;SafeControls&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;Step 3: Create a SharePoint Content Page SPDummy.aspx to host the DummySPWebPart. The source code of SPDummy.aspx is as the following&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Register assembly=&amp;quot;SPDummy&amp;quot; namespace=&amp;quot;SPDummy&amp;quot; tagprefix=&amp;quot;SPDummy&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt; &lt;span style="color: #ff0000"&gt;dir&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ltr&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;form1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SPDummy:DummySPWebPart&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;Now, open SPDummy.aspx in the SharePoint site in a browser. You will get the following:&lt;/div&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/Sc6aKFoDEUI/AAAAAAAAATw/7z-CAMRU914/s1600-h/image%5B8%5D.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="383" alt="image" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Sc6aLFuSrTI/AAAAAAAAAT0/xyCUDGjewJU/image_thumb%5B4%5D.png?imgmax=800" width="632" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;The exception thrown is caused by invoking SPContext.Current.Site.RootWeb.Title, which requests for the CAS permission of type 'Microsoft.SharePoint.Security.SharePointPermission&amp;#8221;. However, the current security policy does not grant the SPDummy.dll the CAS permission. In Lab 3, we will grant the CAS &amp;#8220;SharePointPermission&amp;#8221; to SPDummy.dll by editing CAS security policy.&lt;/p&gt;

&lt;p&gt;Lab 3: Step by step guide on editing CAS&lt;/p&gt;

&lt;p&gt;Step 1: Create a custom policy file wss_custom.config by copying the out-of-box policy file 
  &lt;br /&gt;a.&amp;#160;&amp;#160;&amp;#160; Open directory &amp;#8220;C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG&amp;#8221;. The directory contains the out-of-box policy files defining Wss_Medium and Wss_Minimal trust levels of SharePoint. 

  &lt;br /&gt;b.&amp;#160;&amp;#160;&amp;#160; Make a copy wss_minimaltrust.config in the same directory and rename it to wss_custom.config.&lt;/p&gt;

&lt;p&gt;Step 2: Refer to the &amp;#8220;wss_custom.config&amp;#8221; policy file from the web.config 
  &lt;br /&gt;a.&amp;#160;&amp;#160;&amp;#160; Add a new trustLevel entry to the web.config. The trustLevel points to the new policy file&amp;#160; wss_custom.config your created in step 1.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;securityPolicy&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;      ......&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;trustLevel&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;WSS_Custom&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;policyFile&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\config\wss_custom.config&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;securityPolicy&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;b.&amp;#160;&amp;#160;&amp;#160; Change &amp;lt;trust level=&amp;quot;WSS_Minimal&amp;quot; originUrl=&amp;quot;&amp;quot; /&amp;gt; to &amp;lt;trust level=&amp;quot;WSS_Custom&amp;quot; originUrl=&amp;quot;&amp;quot; /&amp;gt;&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;trust&lt;/span&gt; &lt;span style="color: #ff0000"&gt;level&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;WSS_Custom&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;originUrl&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;After the first two steps, your sharepoint web application starts to use the custom poplicy file, wss_custom.config. Rememeber the &amp;#8220;wss_custom.config&amp;#8221; is just a copy of the out-of-box &amp;#8220;wss_minimaltrust.config&amp;#8221;. Now, we need to modify the file.&lt;/p&gt;

&lt;p&gt;Step 3: Modify the &amp;#8220;wss_custom.config&amp;#8221; policy file so the Dlls in bin directory of the sharepoint web application have CAS SharepointPermission. You just need to add one IPermission element to an existing permissionset element as the follows:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;PermissionSet&lt;/span&gt;  &lt;span style="color: #ff0000"&gt;class&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;NamedPermissionSet&amp;quot;&lt;/span&gt;  &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SPRestricted&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;&amp;lt;!-- add the following element --&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;IPermission&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt; &lt;span style="color: #ff0000"&gt;class&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt; &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt; &lt;span style="color: #ff0000"&gt;ObjectModel&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;&amp;lt;!-- end of the element --&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;PermissionSet&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Save your change and open SPDummy.aspx. Now, it works without any exception!&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/Sc6aLtEFqRI/AAAAAAAAAT4/8UP-MlTEfCI/s1600-h/image%5B11%5D.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="118" alt="image" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Sc6aMaYlc4I/AAAAAAAAAT8/YfEAwQaF0aY/image_thumb%5B5%5D.png?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;How did I figure out to add the SharePointPermission to the SPRestricted permissionset? First, the exception message already tells you that we need to add SharePointPermission. So, you need to add IPermission element with SharePointPermission as its class.You can just use Version=&amp;#8221;1&amp;#8221;. The real catch is how to figure out adding ObjectModel=&amp;#8221;true&amp;#8221;. Go to &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.security.sharepointpermission_properties.aspx"&gt;http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.security.sharepointpermission_properties.aspx&lt;/a&gt;. You notice the SharePointPermission is a .NET class with three public properties. ObjectModel is one of them. What I did was to try each property and assign them to true. After a few tries, ObjectModel=&amp;#8221;True&amp;#8221; is the only one that really matters. There is no silver bullet here. 

  &lt;br /&gt;You should also ask why I choose to add it to SPRestricted PermissionSet. This requires a basic understanding of the structure of the CAS Policy file. Do a search on &amp;#8220;SPRestricted&amp;#8221; in the WSS_custom.config file. You will find the following element:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;CodeGroup&lt;/span&gt; &lt;span style="color: #ff0000"&gt;class&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;UnionCodeGroup&amp;quot;&lt;/span&gt;  &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;PermissionSetName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SPRestricted&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;IMembershipCondition&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    &lt;span style="color: #ff0000"&gt;class&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;UrlMembershipCondition&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    &lt;span style="color: #ff0000"&gt;Url&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;$AppDirUrl$/*&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;CodeGroup&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This is the code group that dictates the CAS permission for all the Dlls under &amp;quot;$AppDirUrl$ directory, which includes the bin directory. This code group uses &amp;#8220;SPRestricted&amp;#8221; permission set. That is why to add the IPermission element to the &amp;#8220;SPRestricted&amp;#8221; permissionset.&lt;/p&gt;

&lt;p&gt;NOTE, the tutorial explains the CAS security in SharePoint. In real world, you should use Windows SharePoint Packaging (WSP) to deploy the changes to CAS policy. This tutorial tells you what happens behind the scene. I will write another blog regarding the deployment in near future.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-3871683526807230619?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/03/sharepoint-trust-level-and-code-access.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_ElXg_EOWn5c/Sc6aJPhWapI/AAAAAAAAATs/zVwVlwV9e2E/s72-c/image_thumb.png?imgmax=800' height='72' width='72'/><thr:total>2</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-5533153477794120986</guid><pubDate>Thu, 26 Feb 2009 14:42:00 +0000</pubDate><atom:updated>2009-02-27T08:50:55.520-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>Develop Security Trimmed navigation Menu for SharePoint</title><description>&lt;p&gt;In my &lt;a href="http://dotnetideasblog.blogspot.com/2009/01/how-to-implement-complex.html"&gt;previous article&lt;/a&gt;,  I explained developing navigation menu in SharePoint using XML file and dataformwebpart. In this log, I will explain how to generate security trimmed navigation menu. To make things even more complex, there are two types of trimming:&lt;/p&gt;&lt;p&gt;1. Still show the menu item in the navigation, but while users click the menu, a message box should pop up and say "You are not authorized to view the page"&lt;/p&gt;&lt;p&gt;2. Will not show the menu item at all.&lt;/p&gt;&lt;p&gt;The solution is to add another SPDataSource to the DataFormWebPart in addition to the XML data source used to retrieve the XML file. (Notice, you are using AggregateSource here) The new datasource will perform a "CrossList" query to all the Pages libraries in the sitecollection. If the current log-in user does not have permission to view a page, the new datasource should not return any record for the page. So, in XSLT code, we just need to perform a filter not to generate menu item for those pages in XML datasource but not returned from the new datasource.&lt;/p&gt;&lt;p&gt;However, we have not solved the problem completely because, for some trimmed pages, we still need to generate menu item and hook up the java script code to display the pop up message box. The solution is to introduce a new attribute to the nodes in the XML file. For example, we can add a boolean attribute "IsGeneratingMessageIfNoPermmission" . The XSLT code will handle the property accordingly.&lt;/p&gt;&lt;p&gt;Once again, it demonstrates using "XML file + DataFormWebpart" to generate navigation menu for sharepoint is a very extensible approach, which fully takes advantage of the power of XSLT and dataformwebprt.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-5533153477794120986?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/02/develop-security-trimmed-navigation.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-6454171627725662114</guid><pubDate>Wed, 04 Feb 2009 15:37:00 +0000</pubDate><atom:updated>2009-02-04T07:37:46.371-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>Why use SharePoint Content Pages instead of Simple ASP.NET pages for transactional page? (The elegant solution for implementing SharePoint user controls.)</title><description>&lt;p&gt;A Page is transactional when the page needs to perform certain actions that require Server Side coding. If you want to implement the page in SharePoint and so End user can change the style of the Page through SharePoint designer, you have to implement the Server Side code in a Custom code behind Page class. You can place all the UI components in the SharePoint page or Page Layout in case of a publishing page. The code behind custom Page class will handle the server side logic. This approach will allow Designers to change the look/feel of the page through SharePoint designer while leaving the server side logic to developer. Allowing Designers to customize without any code change is the advantage to use SharePoint here.&lt;/p&gt;  &lt;p&gt; The problem with this approach is that the Server Side logic is tied up with the page and so is not so reusable. What presented here is to use &amp;#8220;Template&amp;#8221; user controls/Custom controls to achieve the same functionality in a more reusable fashion. Basically, the all the UI components will be inside the &amp;#8220;Template&amp;#8221; properties of the User/Custom Controls. Therefore, they can be placed inside the SharePoint Page and End users can customize the templates through SharePoint designer.&lt;/p&gt;  &lt;p&gt;It is not a new idea.&amp;#160; It is exactly what ASP.Net &amp;#8220;template&amp;#8221; is designed for. It allows customized UI tied up to the same Server Side Logic. A good example is ASP.NET 2.0 login control, in which you can customize the layout of all the UI components while using for the same server side logic. The same idea applies perfectly in the context of SharePoint. SharePoint allows Users to customize the UI components through SharePoint designer while allowing certain degree of Server Side Activities. So, while writing User Controls for SharePoint projects, think about exposing &amp;#8220;Template&amp;#8221; properties and make them customizable through SharePoint Designer.&lt;/p&gt;  &lt;p&gt;It is not so difficult to write a &amp;#8220;template&amp;#8221; controls. Please follow the link to learn how to add templates to a ASP.NET user controls &lt;a href="http://weblogs.asp.net/scottgu/archive/2006/06/04/Supporting-Templates-with-ASP.NET-User-Controls.aspx"&gt;http://weblogs.asp.net/scottgu/archive/2006/06/04/Supporting-Templates-with-ASP.NET-User-Controls.aspx&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-6454171627725662114?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/02/why-use-sharepoint-content-pages.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-6713728892513705030</guid><pubDate>Wed, 28 Jan 2009 22:59:00 +0000</pubDate><atom:updated>2009-01-28T15:00:08.042-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>Integrate SharePoint Security with Line of Business (LOB) application</title><description>&lt;p&gt;We have a legacy line of business web application. The application provides working platforms for various subscribers. We want to migrate the application to use SharePoint as its front-end and so to leverage SharePoint's site provisioning capability as well as other cool features such as customizable web part pages, survey/task list and so on.&lt;/p&gt;  &lt;p&gt;As to security, the LOB has its own set of permissions, groups and users. All of them are stored in its custom database tables. SharePoint has its own concept of users, groups, permissions and permission levels. How to implement a security architecture to cover both of them? Before answering this question, we need to choose where to store all the LOB data. Should we store all of them in sharepoint lists/libraries? It is an easy decision because the LOB has a too complex relational database for SharePoint to handle. The CAML query and Search provided by SharePoint are more like a Meta data search facility, which are not very helpful for handling relational/transactional data. So, most of the transactional relational data should stay in the LOB database and the sharepoint security won't apply to those data. Therefore, we need to implement a security architecture to cover both sharepoint data and the LOB data. Essentially, the security architecture should allow to assign both sharepoint and custom permission to users. For example, We can say &amp;quot;User ABC&amp;quot; can &amp;quot;view web part&amp;quot; pages and &amp;quot;make purchase of product XYZ&amp;quot;.&lt;/p&gt;  &lt;p&gt;The overall architecture is as the following:&lt;/p&gt;  &lt;p&gt;1: Use out-of-box ASP.NET form authentication's SQL membership and SQL role provider. (Notice, we choose not to create a custom security providers.) &lt;/p&gt;  &lt;p&gt;2: Create database tables in the LOB database to map a ASP.NET form user to LOB permissions such as make &amp;quot;purchase of product XYZ&amp;quot;.&lt;/p&gt;  &lt;p&gt;3: Create custom sharepoint admin pages for managing ASP.NET users, roles and assigning both sharepoint permission levels and LOB permissions to them.&amp;#160; &lt;/p&gt;  &lt;p&gt;The code logic behind those admin pages is straightforward. For example, The logic flow to create an user group and assign permissions to the group is as the following:&lt;/p&gt;  &lt;p&gt;1: Use ASP.NET role API to create an ASP.NET role. (ASP.NET role is basically a user group)&lt;/p&gt;  &lt;p&gt;2: Use SharePoint object model API to map the ASP.NET role to a SharePoint User.&lt;/p&gt;  &lt;p&gt;3: Assign the corresponding Permission Levels to the SharePoint User.&lt;/p&gt;  &lt;p&gt;4: To assign LOB permissions to the ASP.NET role, use LINQ to SQL (the latest ASP.NET 3.5 dataaccess API) to update the LOB tables &lt;/p&gt;  &lt;p&gt;The whole process is straightforward and simple as long as you have a clear understanding on ASP.NET form security and SharePoint Security. &lt;/p&gt;  &lt;p&gt;Some of the key points that help to come to the design are:&lt;/p&gt;  &lt;p&gt;1: ASP.NET role provider is essentially &amp;quot;Membership Group&amp;quot;. It is not responsible for mapping a &amp;quot;Membership Group&amp;quot; to &amp;quot;Security Permissions&amp;quot;. A Membership Group determines who are in the group. It does not know what permissions the group has.&lt;/p&gt;  &lt;p&gt;2: SharePoint Permission Levels are &amp;quot;Permission Group&amp;quot;. &lt;/p&gt;  &lt;p&gt;3: LOB have its own permissions.&lt;/p&gt;  &lt;p&gt;4: The security architecture is to Reuse the &amp;quot;Membership Group&amp;quot; feature from ASP.NET role provider and use custom coding to map the ASP.NET role to SharePoint permission levels and LOB permissions.&lt;/p&gt;  &lt;p&gt;It is often confusing about different terminologies such as group, role, permission level and so on. Try to translate those terminologies into a common language such as Permission, Permission Group and Membership Group. Distinguishing Permission Group from Membership Group and understanding the process to assign Permissions/Permission Groups to Membership Group&amp;#160; are very important. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-6713728892513705030?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/01/integrate-sharepoint-security-with-line.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-8036326118623615021</guid><pubDate>Fri, 23 Jan 2009 19:35:00 +0000</pubDate><atom:updated>2009-01-23T11:36:42.614-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>How to author Movie/Flash in SharePoint Publishing Site with minimum coding</title><description>&lt;p&gt;Displaying Movie content is a common requirement in a Publishing Site. The typical behavior is as the following:&lt;/p&gt;  &lt;p&gt;In Authoring/Edit Mode, content authors can choose which movies to display.&lt;/p&gt;  &lt;p&gt;In Display Mode, end users will see the movie or just a link to the movie, clicking the link will pop up a dialog to show the movie.&lt;/p&gt;  &lt;p&gt;The behavior is very similar to the out of box &amp;#8220;RichLinkField&amp;#8221; (Publishing Hyperlink). Actually, they have the exact same Edit Mode behavior. The only difference is that &amp;#8220;Publishing Hyperlink&amp;#8221; will render Anchor link in display Mode whereas Displaying Movie needs to render different HTML segment depending on how to play movie.&lt;/p&gt;  &lt;p&gt;So, instead of building a custom SharePoint Field Type, we just need to build a custom SharePoint field control, which inherits from out-of-box &amp;#8220;RichLinkField&amp;#8221; class and overrides &amp;#8220;RenderFieldForDisplay&amp;#8221; method. The field control will present the same Edit Mode behavior as Publishing Hyperlink while in Display model; it renders the HTML/JavaScript for displaying Movie.&lt;/p&gt;  &lt;p&gt;The approach is very simple and effective. It demonstrates the power of SharePoint&amp;#8217;s extensibility.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-8036326118623615021?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/01/how-to-author-movieflash-in-sharepoint.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-1713490415637050081</guid><pubDate>Fri, 23 Jan 2009 14:49:00 +0000</pubDate><atom:updated>2009-01-23T06:51:20.394-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>How to implement complex Menus/Breadcrumbs/Navigation structure in a SharePoint environment?</title><description>&lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal"&gt;It is natural to try to use out-of-box components such as navigation providers, site map data sources and menu controls. However, it is very often&lt;span style="mso-spacerun: yes"&gt;&amp;#160; &lt;/span&gt;true for a complex content management SharePoint project that the out-of-box features are not enough. There are typically two reasons&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;1.&lt;span style="font: 7pt " times new roman""&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;The logical structure is different from what out-of-box could envisioned or &lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;2.&lt;span style="font: 7pt " times new roman""&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;The custom CSS/JSScript involved is just too complex to be expressed in configuration parameter on out-of-box menu controls. &lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal"&gt;Notice, typically SharePoint developers do not have control on those factors since, for a complex project, web designs typically come from third party companies specialized in web design.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal"&gt;The solution, which proves to be successfully in several projects, is to use a XML file to define the site structure and use DataFormWebPart (Data View Web Part) to generate the HTML/CSS/Java script for the menus and even breadcrumb. &lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal"&gt;In the XML file (Site Map), each node may have an attribute for the URL to the page and some other Meta data attributes to help generate menus. For example, if a node should be only visible for certain groups of user, you can add an attribute to the node to specify the groups. Adding Meta data in the XML file is an extensible approach since you can add a new attribute easily. It is also a maintainable approach due to its centralized nature. Adding Meta data in publishing page content type is an alternative. However, it is decentralized and typically difficult to maintain. &lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal"&gt;With the XML file defining the complex logic structure, all you need to do is to convert it to HTML/CSS/JavaScript. Then, both problems mentioned earlier are solved. XSLT is the perfect candidate for this convertion and therefore DataFormWebPart can be used. In a publishing web site, you can simply put the XML file in style library and use DataFormWebPart to get its content. To this end, &lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;a solid understanding of DataFormWebPart is a necessary. This is not a DataFormWebPart tutorial. Here are a few concepts you can use to quiz how well you understand DataViewWebPart.&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 40.7pt; text-indent: -0.25in; line-height: normal; mso-add-space: auto; mso-list: l0 level1 lfo1"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;1.&lt;span style="font: 7pt " times new roman""&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;How to define a SPDataSource to query data from a list by Name.&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 40.7pt; text-indent: -0.25in; line-height: normal; mso-add-space: auto; mso-list: l0 level1 lfo1"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;2.&lt;span style="font: 7pt " times new roman""&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;SPDataSource supports two modes of Query. Which are they?&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 40.7pt; text-indent: -0.25in; line-height: normal; mso-add-space: auto; mso-list: l0 level1 lfo1"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;3.&lt;span style="font: 7pt " times new roman""&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;How to define an aggregate data source.&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 40.7pt; text-indent: -0.25in; line-height: normal; mso-add-space: auto; mso-list: l0 level1 lfo1"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;4.&lt;span style="font: 7pt " times new roman""&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;How to use PostBack parameter binding.&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 40.7pt; text-indent: -0.25in; line-height: normal; mso-add-space: auto; mso-list: l0 level1 lfo1"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;5.&lt;span style="font: 7pt " times new roman""&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;How to use a control parameter binding.&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpLast" style="margin: 0in 0in 0pt 40.7pt; text-indent: -0.25in; line-height: normal; mso-add-space: auto; mso-list: l0 level1 lfo1"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;6.&lt;span style="font: 7pt " times new roman""&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;How to reuse XSLT in two fashions, utility and framework.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal"&gt;If answers are &amp;#8220;yes&amp;#8221; to all of them and you also have good SharePoint designer experience, you are definitely ready to consider DataFromWebPart as an important part of your SharePoint site architecture.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal"&gt;Notice, item 6, &amp;#8220;how to reuse XSLT in two fashions&amp;#8221;, is crucial if your XSLT code exceeds a few hundred lines. With DataFormWebPart, you can use XSLT &amp;#8220;import&amp;#8221; to reuse the templates/variables from other XSLT files. (I have seen some blog saying it is not possible, which is not correct.). You can achieve &amp;#8220;FrameWork&amp;#8221; like reuse based on the following feature of XSLT:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal"&gt;A template will override the ones with the same name but defined before it. For example, you can have a XSLT file &amp;#8220;FA&amp;#8221; defined a template &amp;#8220;TA&amp;#8221;, which invokes template &amp;#8220;TB&amp;#8221;. You can provide a default implementation for &amp;#8220;TB&amp;#8221; in &amp;#8220;FA&amp;#8221;. Another XSLT file &amp;#8220;FB&amp;#8221; can import &amp;#8220;FA&amp;#8221; and provide a different implementation of &amp;#8220;TB&amp;#8221;. &lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal"&gt;&amp;#8220;Framework&amp;#8221; style reuse is very powerful. It is just like the &amp;#8220;virtual&amp;#8221; function in object oriented programming.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-1713490415637050081?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/01/how-to-implement-complex.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item></channel></rss>