<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.iis.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:cs="http://blogs.iis.net/"><channel><title>Search results matching tags 'Code' and 'IIS'</title><link>http://blogs.iis.net/search/SearchResults.aspx?o=DateDescending&amp;tag=Code,IIS&amp;orTags=0</link><description>Search results matching tags 'Code' and 'IIS'</description><dc:language>en-US</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Improving Time-Critical Code written in C</title><link>http://blogs.iis.net/tomchris/archive/2008/09/02/improving-time-critical-code-written-in-c.aspx</link><pubDate>Tue, 02 Sep 2008 10:00:33 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:2595111</guid><dc:creator>Anonymous</dc:creator><cs:applicationKey>tomchris</cs:applicationKey><description>&lt;p&gt;Writing web pages is very similar to writing any other type of code.&amp;#160; You have to understand how it is going to be used and where you need to really make things run as quickly as possible.&lt;/p&gt;  &lt;p&gt;There are a number of tips on this blog already that deal with managed code and ways to optimize it.&amp;#160; But one of the things that we don't look at as often are other areas of code that we are dependant on.&amp;#160; For example, if you P/Invoke a native function, whatever it is doing, is something that you need to be aware of.&amp;#160; Because there is a lot of native functionality that is still available to us, I wanted to remind everyone of some of the tips you can use when dealing with C/C++ code.&lt;/p&gt;  &lt;p&gt;A great place to start is with: &lt;a title="http://msdn.microsoft.com/en-us/library/eye126ky.aspx" href="http://msdn.microsoft.com/en-us/library/eye126ky.aspx"&gt;Tips for Improving Time-Critical Code&lt;/a&gt;.&amp;#160; While most of these things don't apply to .NET based code, they are all very important when working with native code.&amp;#160; Another useful thing to be aware of is what the compiler can do for you.&amp;#160; For example, take a look at &lt;a title="http://msdn.microsoft.com/en-us/library/aa290055.aspx" href="http://msdn.microsoft.com/en-us/library/aa290055.aspx"&gt;Optimizing Your Code with Visual C++&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Feel free to add your own tips or pointers here.&amp;#160; I'd like to get a good collection going and then I can share that out as well.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8916635" width="1" height="1"&gt;</description></item><item><title>Debugging .NET Framework Source Code</title><link>http://blogs.iis.net/tomchris/archive/2008/05/13/debugging-net-framework-source-code.aspx</link><pubDate>Tue, 13 May 2008 12:45:10 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:2354800</guid><dc:creator>Anonymous</dc:creator><cs:applicationKey>tomchris</cs:applicationKey><description>&lt;p&gt;I am not sure how many people are familiar with the .NET Reference Source project, but if you do a lot of debugging of .NET code, chances are that you have had a situation where you wanted to be able to step into the .NET Source from within Visual Studio.&lt;/p&gt;  &lt;p&gt;Well, thanks to this project.&amp;#160; This is now something that you can accomplish.&amp;#160; It just takes a few steps and you will be off and running.&lt;/p&gt;  &lt;p&gt;I don’t want to go into the specific steps to get this setup as Shawn did a fantastic job explaining them on his blog &lt;a href="http://blogs.msdn.com/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx"&gt;here&lt;/a&gt;.&amp;#160; This is also mentioned on &lt;a href="http://weblogs.asp.net/scottgu/archive/2008/01/16/net-framework-library-source-code-now-available.aspx"&gt;ScottGu’s blog&lt;/a&gt; with another example.&lt;/p&gt;  &lt;p&gt;This is a big win for everyone.&amp;#160; If you have any problems with this and Shawn’s blog doesn’t have your issue documented, feel free to post it here or on the &lt;a href="http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=2019&amp;amp;SiteID=1"&gt;MSDN Forum&lt;/a&gt;.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Keep in mind that you view this through a read-only reference license so feel free to look at the code.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblogs.msdn.com%2ftom%2farchive%2f2008%2f05%2f13%2fdebugging-net-framework-source-code.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblogs.msdn.com%2ftom%2farchive%2f2008%2f05%2f13%2fdebugging-net-framework-source-code.aspx" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8500106" width="1" height="1"&gt;</description></item><item><title>Visual Studio Designer not Respecting Assembly Binding Redirection</title><link>http://blogs.iis.net/tomchris/archive/2008/04/24/visual-studio-designer-not-respecting-assembly-binding-redirection.aspx</link><pubDate>Thu, 24 Apr 2008 19:16:33 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:2319889</guid><dc:creator>Anonymous</dc:creator><cs:applicationKey>tomchris</cs:applicationKey><description>&lt;p&gt;So we recently came across an issue where Visual Studio 2005 and 2008 Designers were not respecting assembly binding redirection.&lt;/p&gt;  &lt;h3&gt;Scenario&lt;/h3&gt;  &lt;p&gt;We have a file which is now version 2 and stored in the &lt;a href="http://msdn2.microsoft.com/en-us/library/yf1d93sz.aspx"&gt;GAC&lt;/a&gt;.&amp;#160; So the assembly version is 2.0.0.0.&amp;#160; We have some existing customers using version 1 so we want to be able to use &lt;a href="http://msdn2.microsoft.com/en-us/library/2fc472t2.aspx"&gt;Assembly Binding Redirection&lt;/a&gt; to point them to the new version of the assembly.&lt;/p&gt;  &lt;p&gt;For more information on configuring this, check out &lt;a href="http://msdn2.microsoft.com/en-us/library/433ysdt1.aspx"&gt;Configuring Assembly Binding Redirection&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The web page has code like:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;tc:TestContacts&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;QuickContacts1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;tc:AContact&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Test Tester&amp;quot;&lt;/span&gt; 
        &lt;span class="attr"&gt;Email&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;test@test.com&amp;quot;&lt;/span&gt; 
        &lt;span class="attr"&gt;Phone&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;(999) 555-1212&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;tc:AContact&lt;/span&gt; &lt;span class="attr"&gt;Email&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;no@spam.thx&amp;quot;&lt;/span&gt; 
        &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Mr. A. Nonymous&amp;quot;&lt;/span&gt; 
        &lt;span class="attr"&gt;Phone&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;(999) 555-1234&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;tc:TestContacts&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;We also have a Register Assembly line at the top that points to the 1.0.0.0 version of the file.&amp;#160; And we have an entry in our web.config that looks like this:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;runtime&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;assemblyBinding&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;urn:schemas-microsoft-com:asm.v1&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;dependentAssembly&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;assemblyIdentity&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Tester1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;publicKeyToken&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;6ace53ab3256c766&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;bindingRedirect&lt;/span&gt; &lt;span class="attr"&gt;oldVersion&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0.0.0-1.1.0.0&amp;quot;&lt;/span&gt;
                             &lt;span class="attr"&gt;newVersion&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;2.0.0.0&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;dependentAssembly&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;assemblyBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;runtime&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;We could have done this in a policy file and got the same results.&amp;#160; So now we open this file in Design view inside Visual Studio and change a property of the TestContacts control.&amp;#160; For instance, adding an AccessKey.&amp;#160; Switching back to the Source view, we will now see:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;tc:TestContacts&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;QuickContacts1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;samples.aspnet.cs.controls.acontact&lt;/span&gt; Name=&amp;quot;Test Tester&amp;quot; 
        Email=&amp;quot;test@test.com&amp;quot; 
        Phone=&amp;quot;(999) 555-1212&amp;quot; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;samples.aspnet.cs.controls.acontact&lt;/span&gt; Email=&amp;quot;no@spam.thx&amp;quot; 
        Name=&amp;quot;Mr. A. Nonymous&amp;quot; 
        Phone=&amp;quot;(999) 555-1234&amp;quot; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;tc:TestContacts&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;This breaks the site and it no longer works.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Note: Assembly Binding Redirection works find in other scenarios, it just doesn’t work right inside the Designer.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;Resolutions&lt;/h3&gt;

&lt;p&gt;There are two ways to resolve this issue.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Don’t use Assembly Binding Redirection at all and just leave the 1.0.0.0 version of the file in the GAC.&amp;#160; You will see a lot of .NET files do this, there are versions for .NET 1.0, 1.1, 2.0, etc all inside the GAC at the same time. &lt;/li&gt;

  &lt;li&gt;Change the existing files so that the Register Assembly line at the top of the web page points to the 2.0.0.0 version of the file. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keep in mind that this is only a problem if you are actively changing the older files already, if you don’t touch the file it will be fine since this issue is only with the Designer.&amp;#160; So since you are already updating the file, it is trivial to update this line also.&lt;/p&gt;

&lt;p&gt;We are looking into this issue also, so there may be another resolution posted in the future.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblogs.msdn.com%2ftom%2farchive%2f2008%2f04%2f24%2fvisual-studio-designer-not-respecting-assembly-binding-redirection.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblogs.msdn.com%2ftom%2farchive%2f2008%2f04%2f24%2fvisual-studio-designer-not-respecting-assembly-binding-redirection.aspx" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8422491" width="1" height="1"&gt;</description></item><item><title>Making an Asynchronous Call using the Impersonation Identity</title><link>http://blogs.iis.net/tomchris/archive/2008/04/22/making-an-asynchronous-call-using-the-impersonation-identity.aspx</link><pubDate>Wed, 23 Apr 2008 02:20:09 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:2315024</guid><dc:creator>Anonymous</dc:creator><cs:applicationKey>tomchris</cs:applicationKey><description>&lt;p&gt;If you try to make an asynchronous call, you will notice that the thread that executes the call doesn't run under the same account as the thread that called it, assuming you are using impersonation.&lt;/p&gt;  &lt;p&gt;There are a number of ways to change this if you would like to have it use the same identity.&lt;/p&gt;  &lt;h4&gt;Method 1&lt;/h4&gt;  &lt;p&gt;The Thread used by BeginInvoke doesn't copy the windowsIdentity from the calling thread. You have to impersonate the new thread manually:    &lt;br /&gt;Before calling BeginInvoke save the current identity into a variable:&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; identity &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; WindowsIdentity
identity = System.Security.Principal.WindowsIdentity.GetCurrent()&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Inside the asynchronously called method use this variable and execute:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;identity.Impersonate&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;From that point on the asynchronous call uses the same privileges than the calling thread and it should not be a problem to execute the callback. 
  &lt;br /&gt;&lt;/p&gt;

&lt;h4&gt;Method 2&lt;/h4&gt;

&lt;p&gt;If the thread making the asynchronous call creates the thread being used, and you are using .NET 2.0 or later, you can set the following in the config file.&amp;#160; For ASP.NET, use the aspnet.config file:&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&amp;lt;configuration&amp;gt;&lt;br /&gt; &amp;lt;runtime&amp;gt;&lt;br /&gt;   &amp;lt;alwaysFlowImpersonationPolicy enabled=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;legacyImpersonationPolicy enabled=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt; &amp;lt;/runtime&amp;gt;&lt;br /&gt;&amp;lt;/configuration&amp;gt;&lt;/pre&gt;

&lt;h4&gt;Method 3&lt;/h4&gt;

&lt;p&gt;Another way to handle this is if you have an account that you want the asynchronous call to run under, you can impersonate that account, run what you need to, and then undo the impersonation.&amp;#160; The following code will do that:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Security.Principal;
...
WindowsIdentity wi = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; WindowsIdentity(userName@fullyqualifieddomainName);
WindowsImpersonationContext ctx = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
&lt;span style="color: #0000ff"&gt;try&lt;/span&gt;
{
  ctx = wi.Impersonate();
  &lt;span style="color: #008000"&gt;// Thread is now impersonating&lt;/span&gt;
}
&lt;span style="color: #0000ff"&gt;catch&lt;/span&gt;
{
  &lt;span style="color: #008000"&gt;// Prevent exceptions propagating.&lt;/span&gt;
}
&lt;span style="color: #0000ff"&gt;finally&lt;/span&gt;
{
  &lt;span style="color: #008000"&gt;// Ensure impersonation is reverted&lt;/span&gt;
  ctx.Undo();
}&lt;/pre&gt;
&lt;/div&gt;

&lt;h4&gt;Additional Information&lt;/h4&gt;

&lt;p&gt;For more information, you can check out these links&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a title="How To- Use Impersonation and Delegation in ASP.NET 2.0" href="http://msdn2.microsoft.com/en-us/library/ms998351.aspx"&gt;How To- Use Impersonation and Delegation in ASP.NET 2.0&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a title="ASP.NET 2.0 Security Questions and Answers - Impersonation" href="http://www.securityguidanceshare.com/index.php?title=ASP.NET_2.0_Security_Questions_and_Answers_-_Impersonation_/_Delegation&amp;amp;printable=yes"&gt;ASP.NET 2.0 Security Questions and Answers - Impersonation&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblogs.msdn.com%2ftom%2farchive%2f2008%2f04%2f22%2fmaking-an-asynchronous-call-using-the-impersonation-identity.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblogs.msdn.com%2ftom%2farchive%2f2008%2f04%2f22%2fmaking-an-asynchronous-call-using-the-impersonation-identity.aspx" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8417771" width="1" height="1"&gt;</description></item></channel></rss>