<?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 'Debugging'</title><link>http://blogs.iis.net/search/SearchResults.aspx?o=DateDescending&amp;tag=Code,Debugging&amp;orTags=0</link><description>Search results matching tags 'Code' and 'Debugging'</description><dc:language>en-US</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><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>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>