<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Dr.NETjes</title><subtitle type="html">Dion Olsthoorn on ASP.NET</subtitle><id>http://weblogs.asp.net/drnetjes/atom.aspx</id><link rel="alternate" type="text/html" href="http://weblogs.asp.net/drnetjes/default.aspx" /><link rel="self" type="application/atom+xml" href="http://weblogs.asp.net/drnetjes/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20510.895">Community Server</generator><updated>2005-06-06T11:50:00Z</updated><entry><title>Great new book on ASP.NET WebParts</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/drnetjes/archive/2007/09/03/great-new-book-on-asp-net-webparts.aspx" /><id>http://weblogs.asp.net/drnetjes/archive/2007/09/03/great-new-book-on-asp-net-webparts.aspx</id><published>2007-09-03T08:17:00Z</published><updated>2007-09-03T08:17:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;I just finished reading the book&amp;nbsp;"&lt;A class="" href="http://www.lulu.com/content/804882" mce_href="http://www.lulu.com/content/804882"&gt;The Web Part Infrastructure Uncovered&lt;/A&gt;" by &lt;A class="" title="Teun Duynstee" href="http://www.teuntostring.net/webpartinfra" mce_href="http://www.teuntostring.net/webpartinfra"&gt;Teun Duynstee&lt;/A&gt; (a colleague of mine) and I think it's the best book available on ASP.NET WebParts. It's well written and contains a lot of interesting code examples.&amp;nbsp;And: it's not expensive (less than $18 at &lt;A class="" href="http://www.lulu.com/content/804882" mce_href="http://www.lulu.com/content/804882"&gt;Lulu.com&lt;/A&gt;).&lt;/P&gt;
&lt;P mce_keep="true"&gt;If you're programming ASP.NET&amp;nbsp;WebParts and you're curious about how to extend the WebPart framework, this is definitely a book to buy. Custom menu's, custom zones, custom security, custom catalog/editor zones, custom property-editors: it's all explained in this book with great examples. Also, Teun explains in detail how the webpart's data is really stored in the database, and how you can create instances of it without the need of a HttpContext. Only thing missing in this book is the integration with&amp;nbsp;ASP.NET Ajax, but there are&amp;nbsp;a lot of good books on Ajax already.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Details on the book&amp;nbsp;here: &lt;A class="" href="http://www.lulu.com/content/804882" mce_href="http://www.lulu.com/content/804882"&gt;The Web Part Infrastructure Uncovered&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3717833" width="1" height="1"&gt;</content><author><name>Dr.NETjes</name><uri>http://weblogs.asp.net/members/Dr.NETjes.aspx</uri></author><category term="WebParts ASP.NET" scheme="http://weblogs.asp.net/drnetjes/archive/tags/WebParts+ASP.NET/default.aspx" /></entry><entry><title>QuickBlog: Free VS2005 template for a weblog application</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/drnetjes/archive/2006/02/10/QuickBlog_3A00_-Free-VS2005-template-for-a-weblog-application.aspx" /><id>http://weblogs.asp.net/drnetjes/archive/2006/02/10/QuickBlog_3A00_-Free-VS2005-template-for-a-weblog-application.aspx</id><published>2006-02-10T09:03:00Z</published><updated>2006-02-10T09:03:00Z</updated><content type="html">&lt;P&gt;Inspired by Scott Guthrie's &lt;A href="http://weblogs.asp.net/scottgu/archive/2005/12/26/433997.aspx" mce_href="http://weblogs.asp.net/scottgu/archive/2005/12/26/433997.aspx"&gt;MyLists example webapplication&lt;/A&gt;, I've made a simple (but fully functional) weblogging application in Visual Studio 2005, which you can &lt;A href="http://home.zonnet.nl/dion.olsthoorn/QuickBlog_Template.zip" mce_href="http://home.zonnet.nl/dion.olsthoorn/QuickBlog_Template.zip"&gt;download here&lt;/A&gt;&amp;nbsp;(all sources included). &lt;/P&gt;
&lt;P&gt;Add this template to your VS2005 VWD ProjectTemplates folder (or just unzip it somewhere and open it with Visual Web Developer). The&amp;nbsp;Visual Web Developer&amp;nbsp;C#-ProjectTemplates folder is default located in &lt;FONT face="Courier New" size=2&gt;\My Documents\Visual Studio 2005\Templates\ProjectTemplates\Visual Web Developer\CSharp&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;Note that I've created this weblog example-application in &lt;STRONG&gt;only 4 hours&lt;/STRONG&gt;(!), and it contains &lt;STRONG&gt;not a single line of code&lt;/STRONG&gt;.&lt;BR&gt;Yep, that's right: 0 lines of code!!!&amp;nbsp; I accomplished this by using:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;SQL2005 Database designer of VS.NET 2005 (no code) &lt;/LI&gt;
&lt;LI&gt;TableAdapter Wizard to create typed datasets&amp;nbsp;(no code) &lt;/LI&gt;
&lt;LI&gt;ObjectDataSources using the typed datasets (no code) &lt;/LI&gt;
&lt;LI&gt;GridView and DetailsView controls to create/read/update/delete postings and comments (no code) &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://www.freetextbox.com/" mce_href="http://www.freetextbox.com/"&gt;FreeTextBox&lt;/A&gt; for richtext creation/editing of postings (no code)&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Features of this QuickBlog webapplication:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Master- and Contentpages &lt;/LI&gt;
&lt;LI&gt;Table-less design &lt;/LI&gt;
&lt;LI&gt;Skinning en Theming &lt;/LI&gt;
&lt;LI&gt;Creating and editing of Postings (by admin) &lt;/LI&gt;
&lt;LI&gt;Readers can add Comments (admin can remove them) &lt;/LI&gt;
&lt;LI&gt;Login control, Membership &lt;/LI&gt;
&lt;LI&gt;A&amp;nbsp;lot of GridViews and DetailsViews &lt;/LI&gt;
&lt;LI&gt;RSS feed &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Some screenshots:&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG style="WIDTH: 834px; HEIGHT: 659px" height=659 src="http://weblogs.asp.net/blogs/drnetjes/quickblog/quickblog_1.jpg" width=834 mce_src="http://weblogs.asp.net/blogs/drnetjes/quickblog/quickblog_1.jpg"&gt;&lt;/P&gt;
&lt;P&gt;Visitor writing a comment:&lt;BR&gt;&lt;IMG style="WIDTH: 834px; HEIGHT: 659px" height=659 src="http://weblogs.asp.net/blogs/drnetjes/quickblog/quickblog_2.jpg" width=834 mce_src="http://weblogs.asp.net/blogs/drnetjes/quickblog/quickblog_2.jpg"&gt;&lt;/P&gt;
&lt;P&gt;After logging on, the admin can manage postings and comments (or create a new posting):&lt;BR&gt;&lt;IMG style="WIDTH: 834px; HEIGHT: 584px" height=584 src="http://weblogs.asp.net/blogs/drnetjes/quickblog/quickblog_3.jpg" width=834 mce_src="http://weblogs.asp.net/blogs/drnetjes/quickblog/quickblog_3.jpg"&gt;&lt;BR&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=437868" width="1" height="1"&gt;</content><author><name>Dr.NETjes</name><uri>http://weblogs.asp.net/members/Dr.NETjes.aspx</uri></author><category term="ASP.NET 2.0 (Whidbey)" scheme="http://weblogs.asp.net/drnetjes/archive/tags/ASP.NET+2.0+_2800_Whidbey_2900_/default.aspx" /></entry><entry><title>MagicAjax.NET online demo's !!</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/drnetjes/archive/2005/12/09/432757.aspx" /><id>http://weblogs.asp.net/drnetjes/archive/2005/12/09/432757.aspx</id><published>2005-12-09T11:02:00Z</published><updated>2005-12-09T11:02:00Z</updated><content type="html">&lt;p&gt;So you want to use &lt;a href="http://www.adaptivepath.com/publications/essays/archives/000385.php"&gt;Ajax&lt;/a&gt; to make your webapplications more interactive and better performing, but you don't want the hassle of writing cross-browser JavaScript?&lt;br /&gt;And you also want to keep using the ASP.NET server-side programming model?&lt;/p&gt; &lt;p&gt;Then open-source &lt;a href="http://www.magicajax.net/"&gt;MagicAjax.NET&lt;/a&gt; is the right solution for you!&lt;/p&gt; &lt;p&gt;MagicAjax is easily integrated&amp;nbsp;in your ASP.NET 1.1 and 2.0 webapplications:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Step 1: Add the MagicAjax HttpModule in your web.config &lt;li&gt;Step 2: You put the part of your page that you want to have Ajax functionality inside an AjaxPanel (&amp;lt;ajax:ajaxpanel&amp;gt;)&lt;/li&gt;&lt;/ul&gt; &lt;p dir="ltr" style="MARGIN-RIGHT: 0px"&gt;That's all you need to do! The MagicAjax framework takes care all of the intrinsic details for you.&lt;/p&gt; &lt;p&gt;We've put together a few example pages to show the power of MagicAjax.NET. See the online demo on &lt;a href="http://demo2.magicajax.net/"&gt;http://demo2.magicajax.net/&lt;/a&gt;&amp;nbsp;(note that the server is sometimes very slow):&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://demo2.magicajax.net/examples/Basic.aspx"&gt;Basic controls using MagicAjax&lt;/a&gt; &lt;li&gt;&lt;a href="http://demo2.magicajax.net/examples/DataGrid.aspx"&gt;DataGrid using MagicAjax&lt;/a&gt; &lt;li&gt;&lt;a href="http://demo2.magicajax.net/examples/MasterDetail.aspx"&gt;GridView &amp;amp; DetailsView using MagicAjax&lt;/a&gt; &lt;li&gt;&lt;a href="http://demo2.magicajax.net/examples/WebParts.aspx"&gt;WebPartManager using MagicAjax&lt;/a&gt; &lt;li&gt;&lt;a href="http://demo2.magicajax.net/examples/Wizard.aspx"&gt;Wizard control using MagicAjax&lt;/a&gt; &lt;li&gt;&lt;a href="http://demo2.magicajax.net/examples/CallbackTimer.aspx"&gt;Windows Processes (using Callback Timer)&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;You can view the sources of all demo pages online, so you can see for yourself how easy it is to use MagicAjax.&lt;br /&gt;Tip: Also have a look at these MagicAjax demo's using FireFox. Fully supported!&lt;/p&gt; &lt;p&gt;Next you see a screenshot of the WebPart Framework&amp;nbsp;in ASP.NET 2.0 using MagicAjax.NET.&lt;br /&gt;Moving, adding and removing of WebParts is all done without a single visual postback; the WebParts just appear on your page!&lt;/p&gt; &lt;p&gt;&lt;img alt="" src="http://home.zonnet.nl/dion.olsthoorn/magicajax_webpartdemo.png" border="0" /&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=432757" width="1" height="1"&gt;</content><author><name>Dr.NETjes</name><uri>http://weblogs.asp.net/members/Dr.NETjes.aspx</uri></author><category term="ASP.NET" scheme="http://weblogs.asp.net/drnetjes/archive/tags/ASP.NET/default.aspx" /><category term="ASP.NET 2.0 (Whidbey)" scheme="http://weblogs.asp.net/drnetjes/archive/tags/ASP.NET+2.0+_2800_Whidbey_2900_/default.aspx" /><category term="MagicAjax" scheme="http://weblogs.asp.net/drnetjes/archive/tags/MagicAjax/default.aspx" /></entry><entry><title>Using Atlas to implement client-side Master-Detail dropdowns</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/drnetjes/archive/2005/10/03/426482.aspx" /><id>http://weblogs.asp.net/drnetjes/archive/2005/10/03/426482.aspx</id><published>2005-10-03T20:51:00Z</published><updated>2005-10-03T20:51:00Z</updated><content type="html">&lt;p&gt;After attending the &lt;a href="http://msdn.microsoft.com/events/pdc/"&gt;PDC&lt;/a&gt;, I thought it would be cool to use &lt;a href="http://atlas.asp.net/"&gt;Atlas&lt;/a&gt; for solving a common postback-overhead problem in ASP.NET :&amp;nbsp;&lt;strong&gt;2 connected&amp;nbsp;Master-Detail dropdown lists&lt;/strong&gt;. &lt;/p&gt; &lt;p&gt;Using plain ASP.NET 1.x, the way to implement this is by setting the 'AutoPostBack' property of the master dropdown to 'true' and then fill the detail dropdown after a postback.&amp;nbsp;But we all know postbacks are slow and bad for user experience; a much better way to solve this problem is&amp;nbsp;by using&amp;nbsp;client-side JavaScript and XML.&lt;/p&gt; &lt;p&gt;An good example (e.g. used by &lt;A href="http://weblogs.asp.net/mschwarz/"&gt;Michael Schwarz&lt;/a&gt; for demonstrating &lt;a href="http://ajax.schwarz-interactive.de/csharpsample/default.aspx"&gt;Ajax.NET&lt;/a&gt;) is the case where the master dropdown shows a list of car brands, and the detail dropdown shows a list of available models for the selected brand. When&amp;nbsp;the user selects a car brand, the car model dropdown is filled clientside, so no need for a postback to the webserver!&lt;br /&gt;&lt;img src="http://home.zonnet.nl/dion.olsthoorn/masterdetail.PNG" border="0" /&gt;&lt;/p&gt; &lt;p&gt;I've assembled an example project containing&amp;nbsp;4 techniques for implementing Master-Detail dropdowns in ASP.NET, which you can &lt;a href="http://home.zonnet.nl/dion.olsthoorn/masterdetail_dropdowns.zip"&gt;download here&lt;/a&gt; (including source code!!!). The 4 techniques in&amp;nbsp;my example project&amp;nbsp;are:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Server-side using ASP.NET 1.x/2.0 AutoPostBack &lt;li&gt;Client-side using ASP.NET 2.0 (beta 2) Client Script Callback &lt;li&gt;Client-side using ASP.NET 1.x/2.0 &lt;a href="http://ajax.schwarz-interactive.de/csharpsample/default.aspx"&gt;Ajax.NET&lt;/a&gt; &lt;li&gt;Client-side using ASP.NET 2.0 (beta 2) &lt;a href="http://atlas.asp.net/"&gt;Atlas script&lt;/a&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Note: For these examples to work, you need &lt;a href="http://lab.msdn.microsoft.com/express/vwd"&gt;ASP.NET 2.0 beta 2&lt;/a&gt; installed. For the examples to run on RC, some changes have to be made for the Client Script Callback example.&lt;br /&gt;Note2: Thanks to &lt;A href="http://weblogs.asp.net/bleroy/"&gt;Bertrand Le Roy&lt;/a&gt; for helping me out on the Atlas code!&lt;/p&gt; &lt;p&gt;A few things I haven't solved for the Atlas example yet:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;The databinding of the detail dropdown needs the selectedValue of the master dropdown. Someway, I can't just bind this value direct from the dropdown, so I used a hidden textbox for this (binded to the selectedValue of the master dropdown). &lt;li&gt;I use the AtlasScript 'setProperty' to enable/disable the postback button. I want to enable the button when the selectedValue of the detail dropdown is unequal to an empty string, but I cant' seem to find a transformation function for a comparison like this.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Please give me feedback when you think my Atlas example could be improved.&lt;/p&gt; &lt;p&gt;&lt;img src="http://home.zonnet.nl/dion.olsthoorn/masterdetai3.PNG" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="http://home.zonnet.nl/dion.olsthoorn/masterdetai4.PNG" border="0" /&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=426482" width="1" height="1"&gt;</content><author><name>Dr.NETjes</name><uri>http://weblogs.asp.net/members/Dr.NETjes.aspx</uri></author><category term="ASP.NET 2.0 (Whidbey)" scheme="http://weblogs.asp.net/drnetjes/archive/tags/ASP.NET+2.0+_2800_Whidbey_2900_/default.aspx" /><category term="Atlas" scheme="http://weblogs.asp.net/drnetjes/archive/tags/Atlas/default.aspx" /></entry><entry><title>Continuous Integration for Visual Studio 2005 Team System beta 2</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/drnetjes/archive/2005/07/20/419957.aspx" /><id>http://weblogs.asp.net/drnetjes/archive/2005/07/20/419957.aspx</id><published>2005-07-20T00:21:00Z</published><updated>2005-07-20T00:21:00Z</updated><content type="html">&lt;p&gt;As you may or may not know, the current beta 2 version of &lt;a href="http://lab.msdn.microsoft.com/teamsystem/default.aspx"&gt;Visual Studio 2005 Team System&lt;/a&gt; only supports &lt;b&gt;manual&lt;/b&gt; team builds against the Team Foundation server. I think&amp;nbsp;the final release of&amp;nbsp;VSTS is going to support scheduled builds (e.g. nightly builds), but I don't think continuous integration will be supported (because Microsoft don't practice CI themselves).&lt;/p&gt; &lt;p&gt;However my company enforces their developers to use &lt;a href="http://www.martinfowler.com/articles/continuousIntegration.html"&gt;Continuous Integration&lt;/a&gt; on all projects, so I had to build a CI process for Team System myself. &lt;br /&gt;I thought it was a good idea to share the results with you :)&lt;/p&gt; &lt;p&gt;I enabled continuous integration by setting up a scheduled MSBuild project that runs every 5 minutes. It includes 4 custom MSBuild Tasks I've created (also see Visio drawing at the bottom): &lt;ul&gt; &lt;li&gt;&lt;b&gt;CheckWorkspaceUpToDate&lt;/b&gt; : Checks if any files were changed on the local server workspace since last run. Uses the h.exe (as of Hatteras) command. &lt;li&gt;&lt;b&gt;StartTeamBuild&lt;/b&gt; : Starts a Team Build by calling the BuildContoller.asmx WebServices (thanks to Aaron Engel for sample code) &lt;li&gt;&lt;b&gt;GetUnexaminedBuild&lt;/b&gt; : If available, returns a finished build from Team Foundation where build quality is "Unexamed". The status of this build will be notified to all team members using messenger, and the build's build quality will be set to 'Notification Sent'. &lt;li&gt;&lt;b&gt;MessengerNotification&lt;/b&gt; : Task to send an arbitrary message through MSN messenger (using SendMSN that uses the DotMSN library; thanks to James Simmonds and B.Geertsema)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;Because you're all such nice people, I decided to share my code and binaries. Download it &lt;a href="http://home.zonnet.nl/dion.olsthoorn/Macaw.MSBuild.Tasks%20(for%20Continuous%20Integration).zip"&gt;here&lt;/a&gt;. &lt;p&gt;To run this Continuous Integration process on your own server, take the following steps: &lt;ol&gt; &lt;li&gt;Create a Team Build using the wizard in Team System (if you already have created a Team Build, skip this step). &lt;li&gt;Create a workspace on your server, and map your project's repository-folder to a local file folder on that server. Do a 'Get Latest' on this folder. &lt;em&gt;Note: first time you do a&amp;nbsp;teambuild, a workspace will automatically be created on the buildserver; it's best to use this generated workspace.&lt;/em&gt; &lt;li&gt;From the downloaded zip, extract "Macaw.MSBuild.Tasks.dll" and "DotMSN.dll" (or build them yourself). Add these libraries to the GAC. &lt;li&gt;From the downloaded zip, extract "/MSBuild Examples/ContinuousIntegration.proj" and put this somewhere on your hard disk (e.g. c:\teambuilder) &lt;li&gt;Edit the ContinuousIntegration.proj MSBuild project, and change all properties in the &amp;lt;PropertyGroup&amp;gt; to match your environment. &lt;li&gt;Test ContinuousIntegration.proj (run as argument of MSBuild.exe, which can be found in the .NET framework folder). &lt;li&gt;If ContinuousIntegration.proj is working well, schedule it to run every 5 minutes: &lt;i&gt;schtasks /create /SC MINUTE /MO 5 /TR &lt;b&gt;[batch file to run]&lt;/b&gt; /TN [scheduled task name]&lt;/i&gt;. Note: The [batch file to run] should contain a command like: "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\MSBuild.exe c:\teambuilder\continuousintegration.proj".&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;/p&gt;&lt;img height="485" alt="" src="http://home.zonnet.nl/dion.olsthoorn/ContinuousIntegration.gif" width="656" border="0" /&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=419957" width="1" height="1"&gt;</content><author><name>Dr.NETjes</name><uri>http://weblogs.asp.net/members/Dr.NETjes.aspx</uri></author><category term="WebServices" scheme="http://weblogs.asp.net/drnetjes/archive/tags/WebServices/default.aspx" /><category term="ASP.NET 2.0 (Whidbey)" scheme="http://weblogs.asp.net/drnetjes/archive/tags/ASP.NET+2.0+_2800_Whidbey_2900_/default.aspx" /><category term="Team System" scheme="http://weblogs.asp.net/drnetjes/archive/tags/Team+System/default.aspx" /></entry><entry><title>FireFox doesn't understand a DOM node-tree?</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/drnetjes/archive/2005/06/23/414712.aspx" /><id>http://weblogs.asp.net/drnetjes/archive/2005/06/23/414712.aspx</id><published>2005-06-23T20:47:00Z</published><updated>2005-06-23T20:47:00Z</updated><content type="html">Have a look at this HTML snippet.&amp;nbsp;When clicking the 'clickme' innerText of div2, I expect the browser to alert "div2", because div2 is the first child of its parent, div1.&lt;font color="#0000ff" size="1"&gt; &lt;p&gt;&lt;font face="Courier New" size="2"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#800000"&gt;div&lt;/font&gt; &lt;font color="#ff0000"&gt;id&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;="div1"&amp;gt;&lt;br /&gt;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;div&lt;/font&gt; &lt;font color="#ff0000"&gt;id&lt;/font&gt;&lt;font color="#0000ff"&gt;="div2"&lt;/font&gt; &lt;font color="#ff0000"&gt;onclick&lt;/font&gt;&lt;font color="#0000ff"&gt;="alert(this.parentNode.childNodes[0].id)"&amp;gt;&lt;/font&gt;clickme&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#800000"&gt;div&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#800000"&gt;div&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;I've tested this HTML snippet on both IE and FireFox, and guess what?&lt;br /&gt;IE reacts as expected by&amp;nbsp;alerting "div2".&lt;br /&gt;However, FireFox alerts "undefined"....?&lt;/p&gt; &lt;p&gt;Apparently, in FireFox&amp;nbsp;div2 is considered&amp;nbsp;to be the &lt;strong&gt;&lt;em&gt;second&lt;/em&gt;&lt;/strong&gt; childNode of div1; not the first. I guess this is because FireFox parses the whitespace between div1 and div2 as&amp;nbsp;being a&amp;nbsp;seperate node! BUT WHY????&lt;/p&gt; &lt;p&gt;Did the creators of FireFox (Mozilla Foundation) implemented this by design? Is it ever going to be fixed in FireFox? Or do we just have to live with it, and write seperate javascript for IE and FireFox?&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;em&gt;[Note: of course I can let IE and FF return the same results by removing all whitespace between the div1 and div2 tags, but that would result in human-unreadable and&amp;nbsp;hard to maintain&amp;nbsp;Html.]&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#008000"&gt;Postscript:&lt;br /&gt;I've received a lot of comments&amp;nbsp;about the fact that&amp;nbsp;FireFox&amp;nbsp;precisely (I'd say 'rigidly') follows the w3c DOM recommendation on this.&amp;nbsp;I'm aware of the w3c specs, but I still think it sucks having to write seperate code for IE and FF (or include a library of wrapper functions).&lt;br /&gt;Personally, I&amp;nbsp;think the IE dom-representation&amp;nbsp;is the more sensible one, whether&amp;nbsp;it's in the recommendation or not.&lt;br /&gt;And FireFox just made a very bad 'first impression' to me :(&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#008000"&gt;Read these links on more information why Mozilla has chosen to preserve whitespaces in the DOM:&lt;/font&gt;&lt;/p&gt; &lt;ul&gt;&lt;font color="#008000"&gt; &lt;li&gt;&lt;a href="https://bugzilla.mozilla.org/show_bug.cgi?id=26179"&gt;https://bugzilla.mozilla.org/show_bug.cgi?id=26179&lt;/a&gt;&amp;nbsp; (the 'whitespace' bug with a lengthy discussion) &lt;li&gt;&lt;a href="http://www.mozilla.org/docs/dom/technote/whitespace/"&gt;http://www.mozilla.org/docs/dom/technote/whitespace/&lt;/a&gt;&amp;nbsp;(Mozilla explaining the issue and giving a poor solution)&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=414712" width="1" height="1"&gt;</content><author><name>Dr.NETjes</name><uri>http://weblogs.asp.net/members/Dr.NETjes.aspx</uri></author></entry><entry><title>Expand/Collapse EditorParts (ASP.NET 2.0 Portal Framework)</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/drnetjes/archive/2005/06/23/414355.aspx" /><id>http://weblogs.asp.net/drnetjes/archive/2005/06/23/414355.aspx</id><published>2005-06-22T22:33:00Z</published><updated>2005-06-22T22:33:00Z</updated><content type="html">&lt;p&gt;If you've been experimenting with the ASP.NET 2.0 Portal Framework (like me!), you know there are 4 out-of-the-box EditorParts that you can place in the EditorZone (the EditorZone is the Zone where you can edit a WebPart's properties). The 4 standard EditorParts are:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;PropertyGridEditorPart &lt;li&gt;AppearanceEditorPart &lt;li&gt;BehaviorEditorPart &lt;li&gt;LayoutEditorPart&lt;/li&gt;&lt;/ul&gt; &lt;h4&gt;The Problem&lt;/h4&gt; &lt;p&gt;These EditorParts work great. However, if you place all 4 EditorParts in the EditorZone, they will show a very long list of editable properties. Not very user-friendly.&lt;/p&gt; &lt;h4&gt;The Solution&lt;/h4&gt; &lt;p&gt;By using stylesheet classes and a&amp;nbsp;little client-side javascript, you can make the EditorParts expand&amp;nbsp;and collapse when you click on&amp;nbsp;their titles. You can even show a cool plus/minus icon next to the EditorPart's title&amp;nbsp;(see screenshot).&lt;/p&gt; &lt;p&gt;&lt;img alt="" src="http://home.zonnet.nl/dion.olsthoorn/expand_collapse.PNG" border="0" /&gt;&lt;/p&gt; &lt;h4&gt;How it's done: The Code&lt;/h4&gt; &lt;p&gt;In the EditorZone tag, set the CssClass-attribute of the EditorParts you want default&amp;nbsp;to be collapsed to 'EditorPartHidden' (this is a css class I'll&amp;nbsp;show you&amp;nbsp;later on). Also set&amp;nbsp;the CssClass of the PartTitleStyle to 'EditorPartTitle' (so a client-side behavior can set on the EditorPart's title).&lt;/p&gt;&lt;font color="#0000ff" size="1"&gt; &lt;p&gt;&lt;font face="Courier New" size="2"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#800000"&gt;asp&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#800000"&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;EditorZone &lt;font color="#ff0000"&gt;runat&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;="server"&amp;nbsp;&lt;font color="#ff0000"&gt;ID&lt;/font&gt;&lt;font color="#0000ff"&gt;="EditorZone1"&lt;/font&gt;&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp; &amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;ZoneTemplate&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;asp&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#800000"&gt;AppearanceEditorPart&lt;/font&gt; &lt;font color="#ff0000"&gt;CssClass&lt;/font&gt;&lt;font color="#0000ff"&gt;="EditorPartHidden"&lt;/font&gt;&amp;nbsp;&lt;font color="#ff0000"&gt;ID&lt;/font&gt;&lt;font color="#0000ff"&gt;="epart1"&lt;/font&gt; &lt;font color="#ff0000"&gt;runat&lt;/font&gt;&lt;font color="#0000ff"&gt;="server"&lt;/font&gt;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;/&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;asp&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#800000"&gt;BehaviorEditorPart&lt;/font&gt; &lt;font color="#ff0000"&gt;CssClass&lt;/font&gt;&lt;font color="#0000ff"&gt;="EditorPartHidden"&lt;/font&gt;&amp;nbsp;&lt;font color="#ff0000"&gt;ID&lt;/font&gt;&lt;font color="#0000ff"&gt;="epart2"&lt;/font&gt;&amp;nbsp;&lt;font color="#ff0000"&gt;runat&lt;/font&gt;&lt;font color="#0000ff"&gt;="server"&lt;/font&gt;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;/&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;asp&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#800000"&gt;LayoutEditorPart&lt;/font&gt; &lt;font color="#ff0000"&gt;CssClass&lt;/font&gt;&lt;font color="#0000ff"&gt;="EditorPartHidden"&lt;/font&gt;&amp;nbsp;&lt;font color="#ff0000"&gt;ID&lt;/font&gt;&lt;font color="#0000ff"&gt;="epart3"&lt;/font&gt; &lt;font color="#ff0000"&gt;runat&lt;/font&gt;&lt;font color="#0000ff"&gt;="Server"&lt;/font&gt;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;/&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp; &amp;lt;/&lt;/font&gt;&lt;font color="#800000"&gt;ZoneTemplate&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" color="#0000ff" size="2"&gt;&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp; &amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;PartTitleStyle&lt;/font&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;CssClass&lt;/font&gt;&lt;font color="#0000ff"&gt;="EditorPartTitle"&lt;/font&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" color="#0000ff" size="2"&gt;/&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#800000" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#800000"&gt;asp&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#800000"&gt;EditorZone&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;font color="#800000" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font color="#800000" size="1"&gt; &lt;p&gt;&lt;font face="Times New Roman" color="#000000" size="3"&gt;Next you can see the 'EditorPartHidden' and 'EditorPartTitle' css classes (put these in your stylesheet). Note that the 'EditorPartTitle' class is using a background image to show the 'plus'&amp;nbsp;sign next to the title (also needs a padding-left to move the title a bit to the right, otherwise the title will be placed on top of the 'plus' sign).&lt;br /&gt;&lt;strike&gt;A behavior (toggle.htc) is set on the EditorPartTitle to perform the expand/collapse. Note: behaviors are&amp;nbsp;IE 5.5+ only (or does FireFox supports this also?).&lt;br /&gt;&lt;/strike&gt;&lt;em&gt;Note: I replaced the .htc (IE only behavior) by cross-browser javascript.&lt;/em&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;.EditorPartHidden&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&lt;font color="#ff0000"&gt;&amp;nbsp; display&lt;/font&gt;: &lt;font color="#0000ff"&gt;none&lt;/font&gt;;&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;&lt;font size="1"&gt;&lt;font color="#800000"&gt; &lt;p&gt;&lt;font size="2"&gt;.EditorPartTitle&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;br /&gt;&lt;font color="#ff0000"&gt;&amp;nbsp; &lt;strike&gt;behavior&lt;/strike&gt;&lt;/font&gt;&lt;strike&gt;: &lt;font color="#0000ff"&gt;url(htc/toggle.htc)&lt;/font&gt;;&lt;/strike&gt; &lt;font color="#008000"&gt;//note: I replaced the .htc (IE only) by cross-browser javascript&lt;/font&gt;&lt;br /&gt;&lt;font color="#ff0000"&gt;&amp;nbsp; background-position&lt;/font&gt;: &lt;font color="#0000ff"&gt;left&lt;/font&gt;;&lt;br /&gt;&lt;font color="#ff0000"&gt;&amp;nbsp; background-repeat&lt;/font&gt;: &lt;font color="#0000ff"&gt;no-repeat&lt;/font&gt;;&lt;br /&gt;&lt;font color="#ff0000"&gt;&amp;nbsp; background-image&lt;/font&gt;: &lt;font color="#0000ff"&gt;url(images/plus.gif)&lt;/font&gt;;&lt;br /&gt;&lt;font color="#ff0000"&gt;&amp;nbsp; cursor&lt;/font&gt;: &lt;font color="#0000ff"&gt;pointer&lt;/font&gt;;&lt;br /&gt;&lt;font color="#ff0000"&gt;&amp;nbsp; padding-left&lt;/font&gt;: &lt;font color="#0000ff"&gt;14px&lt;/font&gt;;&lt;br /&gt;&lt;font color="#ff0000"&gt;&amp;nbsp; font-size&lt;/font&gt;: &lt;font color="#0000ff"&gt;x-small&lt;/font&gt;;&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="1"&gt; &lt;p&gt;&lt;font face="Times New Roman" color="#000000" size="3"&gt;...and this is the javascript code for the expand/collapse behavior. It sets onclick events to all EditorPart titles, which toggles the image (plus/minus) and the EditorPart's content. Include this code on your .aspx page (or use Page.ClientScript.RegisterClientScriptBlock).&lt;/font&gt;&lt;/p&gt;&lt;font size="2"&gt;&lt;font size="1"&gt; &lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;script&lt;/font&gt; &lt;font color="#ff0000"&gt;type&lt;/font&gt;&lt;font color="#0000ff"&gt;="text/javascript"&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#008000"&gt;&amp;nbsp; // Create expanding titles for Legends with className 'EditorPartTitle'&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp; function&lt;/font&gt; CreateExpandingTitles() {&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var&lt;/font&gt; elements = document.getElementsByTagName(&lt;font color="#800000"&gt;"LEGEND"&lt;/font&gt;);&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for&lt;/font&gt; (i=0; i&amp;lt;elements.length; i++) {&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/font&gt; (elements[i].className &amp;amp;&amp;amp; elements[i].className == &lt;font color="#800000"&gt;"EditorPartTitle"&lt;/font&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elements[i].onclick = &lt;font color="#0000ff"&gt;new&lt;/font&gt; Function(&lt;font color="#800000"&gt;"toggle(this);"&lt;/font&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; }&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#008000"&gt;&amp;nbsp; // Call function CreateExpandingTitles on window onload&lt;br /&gt;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt; (window.addEventListener)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; window.addEventListener(&lt;font color="#800000"&gt;'load'&lt;/font&gt;, CreateExpandingTitles, &lt;font color="#0000ff"&gt;false&lt;/font&gt;);&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp; else&lt;/font&gt; &lt;font color="#0000ff"&gt;if&lt;/font&gt; (window.attachEvent)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; window.attachEvent(&lt;font color="#800000"&gt;'onload'&lt;/font&gt;&lt;font size="1"&gt;&lt;font size="2"&gt;, CreateExpandingTitles);&lt;/font&gt;&lt;/p&gt;&lt;/font&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#0000ff"&gt;&amp;nbsp; function&lt;/font&gt; toggle(titleElement) {&lt;br /&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Find nextSibling's firstChild (i.e. DIV with class 'EditorPartStyleHidden')&lt;br /&gt;&lt;/font&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // For IE this is nextSibling.childNodes[0], but due to an error in current&lt;br /&gt;&lt;/font&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // version of FireFox (1.0.4) this is nextSibling.childNodes[1]&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var&lt;/font&gt; firstChild = (titleElement.nextSibling.childNodes[0].id)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ? titleElement.nextSibling.childNodes[0] &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : titleElement.nextSibling.childNodes[1];&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Toggle image and show/hide EditorPart display &lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/font&gt; (firstChild.style.display == &lt;font color="#800000"&gt;"block"&lt;/font&gt;) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; firstChild.style.display = &lt;font color="#800000"&gt;"none"&lt;/font&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; titleElement.style.backgroundImage = &lt;font color="#800000"&gt;"url(images/plus.gif)"&lt;/font&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;font color="#0000ff"&gt;else&lt;/font&gt; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; firstChild.style.display = &lt;font color="#800000"&gt;"block"&lt;/font&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; titleElement.style.backgroundImage = &lt;font color="#800000"&gt;"url(images/minus.gif)"&lt;/font&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#800000"&gt;script&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=414355" width="1" height="1"&gt;</content><author><name>Dr.NETjes</name><uri>http://weblogs.asp.net/members/Dr.NETjes.aspx</uri></author><category term="ASP.NET 2.0 (Whidbey)" scheme="http://weblogs.asp.net/drnetjes/archive/tags/ASP.NET+2.0+_2800_Whidbey_2900_/default.aspx" /></entry><entry><title>Copy &amp; Paste WebParts (ASP.NET 2.0 portal framework)</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/drnetjes/archive/2005/06/17/413518.aspx" /><id>http://weblogs.asp.net/drnetjes/archive/2005/06/17/413518.aspx</id><published>2005-06-17T11:33:00Z</published><updated>2005-06-17T11:33:00Z</updated><content type="html">&lt;p&gt;Some developers in the &lt;a href="http://forums.asp.net/default.aspx?ForumGroupID=26"&gt;ASP.NET 2.0 Forums&lt;/a&gt; have asked questions on how to copy a WebPart (including it's configuration) from one page to another.&lt;/p&gt; &lt;p&gt;The&amp;nbsp;standard solution for this is to use the&amp;nbsp;'Export/Import' functionality&amp;nbsp;that ASP.NET 2.0 offers for WebParts. Note:&amp;nbsp;for a WebPart to be export-enabled, its 'ExportMode' property should have a value other than 'None' (which is the default) and&amp;nbsp;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;font color="#ff0000"&gt;enableExport&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;true&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;should&amp;nbsp;be set in the webParts section of the web.config. The export and import of a (configured) WebPart is done in six steps:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Switch to EditDisplayMode &lt;li&gt;Select 'Export' from the verbs menu of the WebPart you want to copy &lt;li&gt;Download the WebPart file to your local PC &lt;li&gt;Navigate to the destination page, switch to CatalogDisplayMode &lt;li&gt;Select the 'Imported Web Part Catalog', and upload the WebPart file &lt;li&gt;Add the uploaded WebPart to a zone&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Not very user-friendly, is it? Most users wouldn't even know what to do with the downloaded Webpart file.&lt;/p&gt; &lt;p&gt;However, the ASP.NET 2.0 portal framework is very extensible, so I've build a custom solution where the user can just 'copy' the WebPart to a serverside 'clipboard' (i.e. the Session object), and 'paste' it from a custom Catalog (which I named the&amp;nbsp;'Copied Web Part Catalog'). So this is done without downloading and uploading WebParts files!&lt;/p&gt; &lt;p&gt;Here's a screenshot of the copy/paste functionality:&lt;/p&gt; &lt;p&gt;&lt;img src="http://home.zonnet.nl/dion.olsthoorn/CopyPasteWebPart_small.png" /&gt;&lt;/p&gt; &lt;p&gt;So you&amp;nbsp;want to&amp;nbsp;know how this is done? I'll show you the code in&amp;nbsp;3 parts:&lt;/p&gt; &lt;h4&gt;Part 1: Add a custom 'Copy' verb to your WebPart code.&lt;/h4&gt;&lt;font size="1"&gt; &lt;p&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#808080"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt; Override the Verbs collection to add the 'copy webpart' verb&lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#808080"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;override&lt;/font&gt; &lt;font color="#008080"&gt;WebPartVerbCollection&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt; Verbs&lt;br /&gt;{&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New" color="#0000ff" size="2"&gt;&amp;nbsp; get&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (_verbs == null&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WebPartVerb myVerb = new WebPartVerb("copy"&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;, OnWebPartCopy);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myVerb.Description = "Copy this WebPart"&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myVerb.Text = "Copy"&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myVerb.ImageUrl = "~/images/CopyVerb.gif"&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _verbs = new WebPartVerbCollection(new WebPartVerb&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;[] { myVerb });&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;font color="#0000ff"&gt;&lt;font color="#000000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;return&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt; _verbs;&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;&lt;font size="1"&gt; &lt;p&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#808080"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt; Called when the user selects 'Copy WebPart' from the verbs menu.&lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt; The selected WebPart is Exported to a xml string, and added to&lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt; a list in the Session. This list is used by the CopiedCatalogPart&lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt; to add the copied WebParts to a new page or zone&lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#808080"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; OnWebPartCopy(&lt;font color="#0000ff"&gt;object&lt;/font&gt; sender, &lt;font color="#008080"&gt;WebPartEventArgs&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt; e)&lt;br /&gt;{&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp; //get reference to WebPart to copy&lt;br /&gt;&lt;/font&gt;&lt;font color="#008080"&gt;&amp;nbsp; WebPart&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt; webPart = e.WebPart;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;//temporarily set ExportMode to 'All' to enable WebPart exporting&lt;br /&gt;&amp;nbsp; //this&amp;nbsp;is a kind of hack, but&amp;nbsp;assumed legitimate because&amp;nbsp;the&amp;nbsp;exported WebPart&lt;br /&gt;&amp;nbsp; //stays on the&amp;nbsp;server (in Session)&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008080"&gt;&amp;nbsp; WebPartExportMode&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt; origExportMode = ExportMode;&lt;br /&gt;&amp;nbsp; webPart.ExportMode = &lt;font color="#008080"&gt;WebPartExportMode&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;.All;&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&lt;font color="#000000"&gt;&lt;br /&gt;&amp;nbsp; &lt;/font&gt;//export WebPart to string&lt;br /&gt;&lt;/font&gt;&lt;font color="#008080"&gt;&amp;nbsp; StringWriter&lt;/font&gt; stringWriter = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;StringWriter&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;();&lt;br /&gt;&lt;font color="#008080"&gt;&amp;nbsp; XmlTextWriter&lt;/font&gt; xmlwriter = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;XmlTextWriter&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;(stringWriter);&lt;br /&gt;&lt;font color="#008080"&gt;&amp;nbsp; WebPartManager&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;.ExportWebPart(webPart, xmlwriter);&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp; string&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt; copiedWebPart = stringWriter.ToString();&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New" color="#008000" size="2"&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; //reset original ExportMode of WebPart&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp; webPart.ExportMode = origExportMode;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;//reset original ExportMode in exported WebPart string&lt;br /&gt;&lt;/font&gt;&lt;font color="#008080"&gt;&amp;nbsp; XmlDocument&lt;/font&gt; doc = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;XmlDocument&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;();&lt;br /&gt;&amp;nbsp; doc.LoadXml(copiedWebPart);&lt;br /&gt;&lt;font color="#008080"&gt;&amp;nbsp; XmlNode&lt;/font&gt; exportModeNode = doc.SelectSingleNode(&lt;font color="#800000"&gt;"//property[@name='ExportMode']"&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;);&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp; if&lt;/font&gt; (exportModeNode != &lt;font color="#0000ff"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; exportModeNode.InnerText = &lt;font color="#0000ff"&gt;this&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;.ExportMode.ToString();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; copiedWebPart = doc.OuterXml;&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&lt;br /&gt;&amp;nbsp; //get or create list of copied WebParts&lt;br /&gt;&lt;/font&gt;&lt;font color="#008080"&gt;&amp;nbsp; List&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;KeyValuePair&lt;/font&gt;&amp;lt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;, &lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&amp;gt;&amp;gt; copiedWebParts;&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp; if&lt;/font&gt; (Context.Session[&lt;font color="#800000"&gt;"COPIED_WEBPART_KEY"&lt;/font&gt;] != &lt;font color="#0000ff"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;)&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; copiedWebParts = (&lt;font color="#008080"&gt;List&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;KeyValuePair&lt;/font&gt;&amp;lt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;, &lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&amp;gt;&amp;gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Context.Session[&lt;font color="#800000"&gt;"COPIED_WEBPART_KEY"&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;];&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New" color="#0000ff" size="2"&gt;&amp;nbsp; else&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; copiedWebParts = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;List&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;KeyValuePair&lt;/font&gt;&amp;lt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;, &lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;&amp;gt;&amp;gt;();&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&lt;br /&gt;&amp;nbsp; //insert new copied WebPart as first on list&lt;br /&gt;&lt;/font&gt;&amp;nbsp; copiedWebParts.Insert(0, &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;KeyValuePair&lt;/font&gt;&amp;lt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;, &lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&amp;gt;(&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string&lt;/font&gt;.Format(&lt;font color="#800000"&gt;"{0} [copied {1}]"&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;,&amp;nbsp;&lt;font color="#0000ff"&gt;this&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;.Title,&amp;nbsp;&lt;font color="#008080"&gt;DateTime&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;.Now.ToLongTimeString()),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; copiedWebPart));&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&lt;br /&gt;&amp;nbsp; //add list to Session&lt;br /&gt;&lt;/font&gt;&amp;nbsp; Context.Session[&lt;font color="#800000"&gt;"COPIED_WEBPART_KEY"&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;] = copiedWebParts;&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt; &lt;h4&gt;Part 2: The CopiedWebPartCatalogPart&lt;/h4&gt;&lt;font color="#0000ff" size="1"&gt; &lt;p&gt;&lt;font face="Courier New" size="2"&gt;using&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt; System;&lt;br /&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt; System.Collections.Generic;&lt;br /&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt; System.Web.UI.WebControls.WebParts;&lt;br /&gt;&lt;font color="#0000ff"&gt;&lt;br /&gt;namespace&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt; myClassLib.CatalogParts&lt;br /&gt;{&lt;br /&gt;&lt;font color="#808080"&gt;&amp;nbsp; ///&lt;/font&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#808080"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;&amp;nbsp; ///&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt; Catalog for reading WebParts copied to the users Session (copy/paste functionality)&lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;&amp;nbsp; ///&lt;/font&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#808080"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp; public&lt;/font&gt; &lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#008080"&gt;CopiedWebPartCatalogPart&lt;/font&gt; : &lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" color="#008080" size="2"&gt;CatalogPart&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&amp;nbsp; {&lt;br /&gt;&lt;font color="#808080"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/font&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#808080"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt; Overrides the Title to display "Copied Web Part Catalog" by default&lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/font&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#808080"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/font&gt; &lt;font color="#0000ff"&gt;override&lt;/font&gt; &lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt; Title&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New" color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string&lt;/font&gt; title = &lt;font color="#0000ff"&gt;base&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;.Title;&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/font&gt; &lt;font color="#0000ff"&gt;string&lt;/font&gt;.IsNullOrEmpty(title) ? &lt;font color="#800000"&gt;"Copied Web Part Catalog"&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt; : title;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New" color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; base&lt;/font&gt;.Title = &lt;font color="#0000ff"&gt;value&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //dictionary to hold the availabe copied webparts&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private&lt;/font&gt; &lt;font color="#008080"&gt;Dictionary&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;WebPartDescription&lt;/font&gt;, &lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&amp;gt; _webparts&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;Dictionary&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;WebPartDescription&lt;/font&gt;, &lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&amp;gt;();&lt;br /&gt;&lt;font color="#808080"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/font&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#808080"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt; Returns the WebPartDescriptions for the catalog part&lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/font&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#808080"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/font&gt; &lt;font color="#0000ff"&gt;override&lt;/font&gt; &lt;font color="#008080"&gt;WebPartDescriptionCollection&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt; GetAvailableWebPartDescriptions()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _webparts.Clear();&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/font&gt; (Context.Session[&lt;font color="#800000"&gt;"COPIED_WEBPART_SESSION_KEY"&lt;/font&gt;] != &lt;font color="#0000ff"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;font color="#008080"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; List&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;KeyValuePair&lt;/font&gt;&amp;lt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;, &lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&amp;gt;&amp;gt; copiedWebParts =&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;font color="#008080"&gt;List&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;KeyValuePair&lt;/font&gt;&amp;lt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;, &lt;font color="#0000ff"&gt;string&lt;/font&gt;&amp;gt;&amp;gt;)Context.Session[&lt;font color="#800000"&gt;"COPIED_WEBPART_SESSION_KEY"&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;];&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach&lt;/font&gt; (&lt;font color="#008080"&gt;KeyValuePair&lt;/font&gt;&amp;lt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;, &lt;font color="#0000ff"&gt;string&lt;/font&gt;&amp;gt; copiedWebPart &lt;font color="#0000ff"&gt;in&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt; copiedWebParts)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;font color="#008080"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WebPartDescription&lt;/font&gt; desc = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;WebPartDescription&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; copiedWebParts.IndexOf(copiedWebPart).ToString(),&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; copiedWebPart.Key,&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; null&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;,&amp;nbsp;&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; null&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _webparts[desc] = copiedWebPart.Value;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/font&gt; &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;WebPartDescriptionCollection&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;(_webparts.Keys);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&lt;font color="#808080"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/font&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#808080"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt; Returns a new instance of the WebPart specified by the description&lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/font&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#808080"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/font&gt; &lt;font color="#0000ff"&gt;override&lt;/font&gt; &lt;font color="#008080"&gt;WebPart&lt;/font&gt; GetWebPart(&lt;font color="#008080"&gt;WebPartDescription&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt; description)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //get a xmltextreader to the exported WebPart&lt;br /&gt;&lt;/font&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Xml.&lt;font color="#008080"&gt;XmlTextReader&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt; reader =&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new&lt;/font&gt; System.Xml.&lt;font color="#008080"&gt;XmlTextReader&lt;/font&gt;(&lt;font color="#0000ff"&gt;new&lt;/font&gt; System.IO.&lt;font color="#008080"&gt;StringReader&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;(_webparts[description]));&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string&lt;/font&gt; errorMessage; &lt;/font&gt;&lt;font face="Courier New" color="#008000" size="2"&gt;//will contain errorMessage on import errors&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //return an instance of the requested WebPart&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/font&gt; &lt;font color="#008080"&gt;WebPartManager&lt;/font&gt;.ImportWebPart(reader, &lt;font color="#0000ff"&gt;out&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt; errorMessage);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt; &lt;h4&gt;Part 3: Add the CopiedWebPartCatalogPart in the CatalogZone of your aspx page&lt;/h4&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font face="Courier New" size="2"&gt;&lt;font size="1"&gt; &lt;p&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;lt;%&lt;font color="#0000ff"&gt;@&lt;/font&gt; &lt;font color="#800000"&gt;Register&lt;/font&gt; &lt;font color="#ff0000"&gt;TagPrefix&lt;/font&gt;&lt;font color="#0000ff"&gt;="myCatalogParts"&lt;/font&gt; &lt;font color="#ff0000"&gt;Assembly&lt;/font&gt;&lt;font color="#0000ff"&gt;="myClassLib"&lt;/font&gt; &lt;font color="#ff0000"&gt;Namespace&lt;/font&gt;&lt;font color="#0000ff"&gt;="myClassLib.CatalogParts"&lt;/font&gt; %&amp;gt;&lt;/font&gt;&lt;font size="1"&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#800000"&gt;asp&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#800000"&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;CatalogZone &lt;font color="#ff0000"&gt;ID&lt;/font&gt;&lt;font color="#0000ff"&gt;="CatalogZone"&lt;/font&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;runat&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font face="Courier New" size="2"&gt;="server" &lt;/font&gt;&lt;font face="Courier New" color="#0000ff" size="2"&gt;&amp;gt;&lt;br /&gt;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;ZoneTemplate&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;asp&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#800000"&gt;PageCatalogPart&lt;/font&gt; &lt;font color="#ff0000"&gt;ID&lt;/font&gt;&lt;font color="#0000ff"&gt;="PagePart"&lt;/font&gt; &lt;font color="#ff0000"&gt;runat&lt;/font&gt;&lt;font color="#0000ff"&gt;="server"&lt;/font&gt; &lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;asp&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#800000"&gt;ImportCatalogPart&lt;/font&gt; &lt;font color="#ff0000"&gt;Visible&lt;/font&gt;&lt;font color="#0000ff"&gt;="false"&lt;/font&gt; &lt;font color="#ff0000"&gt;ID&lt;/font&gt;&lt;font color="#0000ff"&gt;="ImportPart"&lt;/font&gt; &lt;font color="#ff0000"&gt;runat&lt;/font&gt;&lt;font color="#0000ff"&gt;="Server"&lt;/font&gt; &lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;strong&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;myCatalogParts&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#800000"&gt;CopiedWebPartCatalogPart&lt;/font&gt; &lt;font color="#ff0000"&gt;ID&lt;/font&gt;&lt;font color="#0000ff"&gt;="PastePart"&lt;/font&gt; &lt;font color="#ff0000"&gt;runat&lt;/font&gt;&lt;font color="#0000ff"&gt;="server"&lt;/font&gt; &lt;/strong&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;strong&gt;/&amp;gt;&lt;/strong&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp; &amp;lt;/&lt;/font&gt;&lt;font color="#800000"&gt;ZoneTemplate&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#800000"&gt;asp&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#800000"&gt;CatalogZone&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;&amp;gt;&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=413518" width="1" height="1"&gt;</content><author><name>Dr.NETjes</name><uri>http://weblogs.asp.net/members/Dr.NETjes.aspx</uri></author><category term="ASP.NET" scheme="http://weblogs.asp.net/drnetjes/archive/tags/ASP.NET/default.aspx" /></entry><entry><title>SiteMapProvider.CurrentNode isn't aware of default.aspx documents in webfolders</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/drnetjes/archive/2005/06/10/411145.aspx" /><id>http://weblogs.asp.net/drnetjes/archive/2005/06/10/411145.aspx</id><published>2005-06-10T09:39:00Z</published><updated>2005-06-10T09:39:00Z</updated><content type="html">&lt;h4&gt;The Problem&lt;/h4&gt; &lt;p&gt;I think the 'default document' option in IIS is a great way to get clean url's without those .aspx extensions. So instead of calling the url 'http://www.mysite.com/news/default.aspx',&amp;nbsp;you could also&amp;nbsp;call 'http://www.mysite.com/news', which will get you to the same page. This is&amp;nbsp;because IIS finds the default document 'default.aspx' in the news folder.&lt;/p&gt; &lt;p&gt;However, the default SiteMapProvider in ASP.NET 2.0 isn't aware of IIS's default documents, and won't highlight the selected node in a Menu or TreeView contol. Take a look at this xml siteMap file; it will result in links to &lt;font face="Courier New" color="#0000ff" size="2"&gt;/default.aspx&lt;/font&gt; and &lt;font face="Courier New" color="#0000ff" size="2"&gt;/news/default.aspx&lt;/font&gt;, but the selected node in my Menu won't be highlighted because the url of the siteMapNode and the request's url don't match:&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt; &lt;p&gt;&lt;font face="Courier New"&gt;&amp;lt;?&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#800000" size="2"&gt;xml&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;version&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;1.0&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;encoding&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;utf-8&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff" size="2"&gt;?&amp;gt;&lt;br /&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000" size="2"&gt;siteMap&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff" size="2"&gt;&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;&lt;/font&gt;&lt;font color="#800000" size="2"&gt;siteMapNode&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;title&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Home&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;url&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;~&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff" size="2"&gt;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/font&gt;&lt;font color="#800000" size="2"&gt;siteMapNode&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;title&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;News&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;url&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;~/news&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff" size="2"&gt; /&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/&lt;/font&gt;&lt;font color="#800000" size="2"&gt;siteMapNode&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff" size="2"&gt;&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#800000" size="2"&gt;siteMap&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;gt;&lt;/p&gt;&lt;/font&gt;&lt;/font&gt; &lt;h4&gt;The Solution&lt;/h4&gt; &lt;p&gt;Luckily for me, ASP.NET 2.0 has a provider model for the SiteMaps. This means I've just got to override the CurrentNode property of the default XmlSiteMapProvider&amp;nbsp;and add&amp;nbsp;extra logic for recognizing default documents. Take a look at the code of my FolderAware_XmlSiteMapProvider:&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt; &lt;p&gt;&lt;font face="Courier New"&gt;using&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt; System;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;using&lt;/font&gt;&lt;font size="2"&gt; System.Web;&lt;/p&gt;&lt;/font&gt;&lt;/font&gt; &lt;p&gt; &lt;p&gt;&lt;font face="Courier New"&gt;&lt;font color="#808080" size="2"&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#008080" size="2"&gt;FolderAware_XmlSiteMapProvider&lt;/font&gt;&lt;font size="2"&gt; : &lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" color="#008080" size="2"&gt;XmlSiteMapProvider&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;{&lt;br /&gt;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;override&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#008080" size="2"&gt;SiteMapNode&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt; CurrentNode&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" color="#0000ff" size="2"&gt;get&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font face="Courier New"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font face="Courier New"&gt;// first let the base resolve the current node&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#008080" size="2"&gt;SiteMapNode&lt;/font&gt;&lt;font size="2"&gt; currentNode = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;base&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;.CurrentNode;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;font size="2"&gt; (currentNode == &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font face="Courier New"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font face="Courier New"&gt;// now check if a node exists that's pointing to a folder, and current&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // RawUrl maps to the folder's default document (default.aspx) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#008080" size="2"&gt;HttpContext&lt;/font&gt;&lt;font size="2"&gt; context = &lt;/font&gt;&lt;font color="#008080" size="2"&gt;HttpContext&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;.Current;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;font size="2"&gt; (context != &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font face="Courier New"&gt;{&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt; text = context.Request.RawUrl.ToLowerInvariant();&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int&lt;/font&gt;&lt;font size="2"&gt; index = text.IndexOf(&lt;/font&gt;&lt;font color="#800000" size="2"&gt;"/default.aspx"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;);&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt; (index != -1)&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;currentNode = FindSiteMapNode(text.Substring(0, index));&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/font&gt;&lt;font size="2"&gt; (currentNode != &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt; &amp;amp;&amp;amp; !currentNode.IsAccessibleToUser(context))&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;currentNode = &lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;;&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt; currentNode;&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&amp;nbsp; }&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;}&lt;/font&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;/font&gt;For your webapplication to use this new FolderAware_XmlSiteMapProvider, you've got to define it in your web.config:&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt; &lt;p&gt;&lt;font face="Courier New"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#800000" size="2"&gt;siteMap&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;defaultProvider&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;FolderAware_XmlSiteMapProvider&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font face="Courier New"&gt;&amp;gt;&lt;br /&gt;&amp;nbsp; &lt;/font&gt;&lt;font face="Courier New"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" color="#800000" size="2"&gt;providers&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font face="Courier New"&gt;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font face="Courier New"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" color="#800000" size="2"&gt;clear&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font face="Courier New"&gt;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font face="Courier New"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#800000" size="2"&gt;add&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;siteMapFile&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;web.sitemap&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;name&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;FolderAware_XmlSiteMapProvider&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;type&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;FolderAware_XmlSiteMapProvider&lt;/font&gt;&lt;font size="2"&gt;" /&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font face="Courier New"&gt;&lt;br /&gt;&amp;nbsp; &lt;/font&gt;&lt;font face="Courier New"&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" color="#800000" size="2"&gt;providers&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font face="Courier New"&gt;&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#800000" size="2"&gt;siteMap&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;...and now the Menu, TreeView and BreadCrumbs&amp;nbsp;contols will highlight the currently selected page even if a request to a webfolder was made!&lt;/p&gt; &lt;p&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=411145" width="1" height="1"&gt;</content><author><name>Dr.NETjes</name><uri>http://weblogs.asp.net/members/Dr.NETjes.aspx</uri></author><category term="ASP.NET 2.0 (Whidbey)" scheme="http://weblogs.asp.net/drnetjes/archive/tags/ASP.NET+2.0+_2800_Whidbey_2900_/default.aspx" /></entry><entry><title>Impersonation inside HttpHandlers</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/drnetjes/archive/2005/06/06/410508.aspx" /><id>http://weblogs.asp.net/drnetjes/archive/2005/06/06/410508.aspx</id><published>2005-06-06T09:50:00Z</published><updated>2005-06-06T09:50:00Z</updated><content type="html">&lt;h4&gt;About impersonating your ASP.NET code&lt;/h4&gt; &lt;p&gt;By using basic or integrated IIS security, you can set the security context on whose behalf the code is running to the current user by adding these two lines in your web.config:&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt; &lt;p&gt;&lt;font face="Courier New"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#800000" size="2"&gt;authentication&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;mode&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Windows&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff" size="2"&gt;/&amp;gt;&lt;br /&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000" size="2"&gt;identity&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;impersonate&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;true&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;/&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;This can be usefull when you want to call WebServices inside you code that needs the current user's credentials (note: you'll need Kerberos authentication not to run into the two-hop problem,&amp;nbsp;see &lt;a href="http://blogs.msdn.com/mjeelani/archive/2004/12/07/275921.aspx"&gt;http://blogs.msdn.com/mjeelani/archive/2004/12/07/275921.aspx&lt;/a&gt;).&lt;/p&gt; &lt;h4&gt;The problem: No impersonation inside HttpHandlers&lt;/h4&gt; &lt;p&gt;While your pages and controls will now run on behalf of the current user,&amp;nbsp;for some reason&amp;nbsp;this impersonation is not done inside your custom&amp;nbsp;HttpHandler! Although the user is authenticated (&lt;font face="Courier New" color="#000000" size="2"&gt;HttpContext.Current.User.IsAuthenticated&lt;/font&gt; is &lt;font face="Courier New" color="#0000ff" size="2"&gt;true&lt;/font&gt;),&amp;nbsp;all code is still running&amp;nbsp;as ASPNET or the default AppPool identity (just add a watch on&amp;nbsp;&lt;font face="Courier New" color="#000000" size="2"&gt;System.Security.Principal.WindowsIdentity.GetCurrent()&lt;/font&gt;). So by calling a WebService inside your HttpHandler code using the &lt;font face="Courier New" size="2"&gt;DefaultCredentials&lt;/font&gt;, the wrong credentials will be passed and you'll probably get a 404.&amp;nbsp; &lt;h4&gt;The solution: Do your own impersonation&lt;/h4&gt;&lt;font color="#0000ff" size="2"&gt; &lt;p&gt;&lt;font face="Courier New"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#008080" size="2"&gt;IHttpHandler&lt;/font&gt;&lt;font size="2"&gt; GetHandler(&lt;/font&gt;&lt;font color="#008080" size="2"&gt;HttpContext&lt;/font&gt;&lt;font size="2"&gt; context, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; requestType, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; url, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt; pathTranslated)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; ...&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;br /&gt;&amp;nbsp; &lt;span style="COLOR: green"&gt;// Create a WindowsImpersonationContext object by impersonating the &lt;/span&gt;&lt;span style="COLOR: green"&gt;Windows identity.&lt;/span&gt;&lt;br /&gt;&amp;nbsp; WindowsImpersonationContext impersonationContext = ((&lt;font color="#008080" size="2"&gt;WindowsIdentity&lt;/font&gt;&lt;font size="2"&gt;)&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;context.User.Identity).Impersonate()&lt;/font&gt;&lt;/font&gt;;&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; &lt;font color="#0000ff"&gt;try&lt;/font&gt;&lt;br /&gt;&amp;nbsp; {&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;em&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;/strong&gt;&lt;/em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/em&gt;&lt;/strong&gt;&lt;span style="COLOR: green"&gt;// Your impersonated calls to WebServices here&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;font color="#000000"&gt;} &lt;br /&gt;&amp;nbsp; &lt;font color="#000080"&gt;&lt;font color="#0000ff"&gt;catch&lt;/font&gt; &lt;/font&gt;{}&lt;br /&gt;&amp;nbsp; &lt;font color="#0000ff"&gt;finally&lt;/font&gt; &lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;if&lt;/font&gt; (impersonationContext&amp;nbsp;!= &lt;font color="#0000ff"&gt;null&lt;/font&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;// always undo impersonation&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; impersonationContext.Undo();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="COLOR: green"&gt;&lt;span style="COLOR: green"&gt;&lt;font color="#000000"&gt;&lt;br /&gt;&amp;nbsp; }&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; ...&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/font&gt; &lt;p&gt;...so, after you impersonate to the identity inside the current &lt;font face="Courier New" size="2"&gt;HttpContext&lt;/font&gt;, your code will now be running on behalf of the currently logged on user, and you can call WebServices using the current user's credentials.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=410508" width="1" height="1"&gt;</content><author><name>Dr.NETjes</name><uri>http://weblogs.asp.net/members/Dr.NETjes.aspx</uri></author><category term="ASP.NET" scheme="http://weblogs.asp.net/drnetjes/archive/tags/ASP.NET/default.aspx" /></entry></feed>