<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>crunchlife: Tag ASPNET</title>
    <link>http://crunchlife.com/articles/tag/aspnet</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Using LoginView on HyperLinkFields within a GridView</title>
      <description>&lt;p&gt;&lt;img src="/files/aspnet.gif" class="right"&gt;The title of this post is a bit misleading. Using a LoginView to manage the security of HyperLinkFields within a GridView does not work. There are, however, other means to achieve the same result.&lt;/p&gt;

&lt;p&gt;Using the GridView&amp;#8217;s OnRowDataBound event, I&amp;#8217;ve set my Cells containing HyperLinkFields, on DataRows with a RowIndex of -1, to an empty string if the user does not belong to the &amp;#8220;Administrators&amp;#8221; role. This hides my HyperLinkFields from underprivileged users and prevents elements of my GridView&amp;#8217;s header and footer from not appearing.&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowIndex != -1)
    {
        if (!Page.User.IsInRole(&amp;quot;Administrators&amp;quot;))        
            e.Row.Cells[0].Text = String.Empty;
    }           
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;*Update&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I just found a &lt;a href="http://forums.asp.net/t/943849.aspx" target="_blank"&gt;thread&lt;/a&gt; on the ASP.NET forums that covers the same problem. In their solution, the GridView&amp;#8217;s RowType is checked before setting the Cell&amp;#8217;s Visibility property to false. This makes more sense than relying on the RowIndex property to determine whether or not a DataRow&amp;#8217;s Cell should be hidden. In the method below, I&amp;#8217;ve integrated the DataControlRowType enumeration as suggested by the ASP.NET forums. Since setting the Visibility property of Cells containing HyperLinkFields caused my GridView headings to not line up properly, I decided to assign the Cell&amp;#8217;s Text property to String.Empty as in my previous example.&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{                  
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (!Page.User.IsInRole(&amp;quot;Administrators&amp;quot;))
            e.Row.Cells[0].Text = String.Empty;
    }   
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
      <pubDate>Wed, 13 Aug 2008 12:45:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:95cccc69-ac5a-417a-aa72-8d64168cd1ab</guid>
      <author>Ryan Baxter</author>
      <link>http://crunchlife.com/articles/2008/08/13/using-loginview-on-hyperlinkfields-within-a-gridview</link>
      <category>Code Snippets</category>
      <category>ASPNET</category>
      <enclosure type="image/gif" url="http://crunchlife.com/files/aspnet.gif" length="3597"/>
    </item>
    <item>
      <title>IE7's Inanimate GIF</title>
      <description>&lt;p&gt;Animated GIFs are most often used as activity indicators in modern &lt;a
href="http://en.wikipedia.org/wiki/Ajax_(programming)"
target="_blank"&gt;AJAX (asynchronous JavaScript and XML)&lt;/a&gt; enabled
websites. I decided to use a &lt;a
href="http://en.wikipedia.org/wiki/Gif" target="_blank"&gt;GIF (Graphic
Interchange Format)&lt;/a&gt; from &lt;a href="http://www.ajaxload.info/"
target="_blank"&gt;ajaxload.info&lt;/a&gt; on an application that I&amp;#8217;ve been
developing at work. The application performs server-side
processing on files uploaded by employees. Processing time varies depending on the size of the file. Larger files take longer.&lt;/p&gt;

&lt;p&gt;I wanted the animated GIF to appear when the file upload button was clicked so I placed the image within a &lt;a href="http://www.w3schools.com/tags/tag_DIV.asp" target="_blank"&gt;DIV&lt;/a&gt; tag and hid it by setting a blank &lt;a href="http://www.w3schools.com/css/pr_class_display.asp" target="_blank"&gt;CSS display property&lt;/a&gt;. OnClick of the upload button, a
JavaScript function toggled the display value to &amp;#8220;block&amp;#8221;, making the DIV appear. This worked as
expected in &lt;a href="http://www.mozilla.com/en-US/firefox/?utm_id=Q108&amp;amp;utm_source=google&amp;amp;utm_medium=ppc&amp;amp;gclid=CPnY35q27JMCFQtvGgodcnzhWg" target="_blank"&gt;Firefox&lt;/a&gt; and IE6, but not in IE7. The DIV appeared in IE7,
but it&amp;#8217;s GIF wasn&amp;#8217;t moving.&lt;/p&gt;

&lt;p&gt;A little googling turned up a helpful comment on &lt;a href="http://west-wind.com/WebLog/default.aspx" target="_blank"&gt;Rick Strahl&amp;#8217;s blog&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
I&amp;#8217;ve run into a problem with animated gifs inside of a hidden area of a Web page that is hidden with style.display=&amp;#8217;none&amp;#8217;. When the area is made visible again, in Internet Explorer this causes the image to not be displayed an animated GIF whatever I try. [sic] 
&lt;/blockquote&gt;

&lt;p&gt;Apparently IE7 doesn&amp;#8217;t like to animate hidden GIFs. User submitted comments on Rick Strahl&amp;#8217;s blog provided many solutions, but only a couple worked in my situation. The first uses the JavaScript setTimeout method to populate the image&amp;#8217;s SRC attribute 200 ms after the function call. The second sets the DIV&amp;#8217;s innerHTML to a string containing an &lt;a href="http://www.w3schools.com/tags/tag_IMG.asp" target="_blank"&gt;IMG&lt;/a&gt; tag with the animated GIF.&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;lt;script language='javascript'&amp;gt; 
    function ShowLoading(elementId) 
    {
        document.getElementById(elementId).style.display = &amp;quot;block&amp;quot;; 
        setTimeout('document.images[&amp;quot;loadingImage&amp;quot;].src = &amp;quot;../images/loading.gif&amp;quot;', 200); 
    } 
&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Neither solution is ideal, but setting the element&amp;#8217;s innerHTML felt a little bit cleaner to me.&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;lt;script language='javascript'&amp;gt;
    function ShowLoading(elementId)
    {   
        var element = document.getElementById(elementId);    

        element.innerHTML = &amp;quot;&amp;lt;img src='../images/loading.gif'&amp;gt;&amp;quot;;    
        element.style.display = &amp;quot;block&amp;quot;;
    }
&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;
*IE7 may have animations disabled. Go to Tools &gt; Internet Options &gt; Advanced &gt; Multimedia. Checking &amp;#8220;Play animations in webpages&amp;#8221; may affect how IE7 renders your animated GIFs.
&lt;/strong&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 11 Jun 2008 05:06:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:a2283586-36cd-4064-8291-8155c59f2cf9</guid>
      <author>Ryan Baxter</author>
      <link>http://crunchlife.com/articles/2008/06/11/ie7s-inanimate-gif</link>
      <category>Code Snippets</category>
      <category>Expect the Unexpected</category>
      <category>ASPNET</category>
      <category>JavaScript</category>
      <trackback:ping>http://crunchlife.com/articles/trackback/68</trackback:ping>
    </item>
    <item>
      <title>Temporary Identity Impersonation in ASP.NET</title>
      <description>&lt;p&gt;Uploading files in an ASP.NET application is relatively easy to do. Uploading to a remote machine is a little bit trickier, but certainly doable. I followed a &lt;a href="http://aspalliance.com/336_Upload_Files_Using_ASPNET_Impersonation_and_UNC_Share.all" target="_blank"&gt;set of instructions&lt;/a&gt; on aspalliance.com, but rather than declare an account to impersonate in my web.config file, I decided to do it in code. That way I could use impersonation only when needed and encapsulate it for later use.&lt;/p&gt;

&lt;p&gt;I referred to an &lt;a href="http://support.microsoft.com/kb/306158#4" target="_blank"&gt;article&lt;/a&gt; on Microsoft&amp;#8217;s Help and Support website about how to implement impersonation. Their code worked great, but I decided to put it in a class to help keep things &lt;a href="http://en.wikipedia.org/wiki/DRY" target="_blank"&gt;DRY&lt;/a&gt;.&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;using System;
using System.Web;
using System.Web.Security;
using System.Security.Principal;
using System.Runtime.InteropServices;

namespace Utilities
{    
    public class ImpersonateUser
    {
        public const int LOGON32_LOGON_INTERACTIVE = 2;
        public const int LOGON32_PROVIDER_DEFAULT = 0;

        WindowsImpersonationContext impersonationContext;

        [DllImport(&amp;quot;advapi32.dll&amp;quot;)]
        public static extern int LogonUserA(String lpszUserName,
            String lpszDomain,
            String lpszPassword,
            int dwLogonType,
            int dwLogonProvider,
            ref IntPtr phToken);
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]
        public static extern int DuplicateToken(IntPtr hToken,
            int impersonationLevel,
            ref IntPtr hNewToken);

        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool RevertToSelf();

        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]
        public static extern bool CloseHandle(IntPtr handle);

        public bool ImpersonateValidUser(String userName, String domain, String password)
        {
            WindowsIdentity tempWindowsIdentity;
            IntPtr token = IntPtr.Zero;
            IntPtr tokenDuplicate = IntPtr.Zero;

            if (RevertToSelf())
            {
                if (LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE,
                    LOGON32_PROVIDER_DEFAULT, ref token) != 0)
                {
                    if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)
                    {
                        tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
                        impersonationContext = tempWindowsIdentity.Impersonate();
                        if (impersonationContext != null)
                        {
                            CloseHandle(token);
                            CloseHandle(tokenDuplicate);
                            return true;
                        }
                    }
                }
            }
            if (token != IntPtr.Zero)
                CloseHandle(token);
            if (tokenDuplicate != IntPtr.Zero)
                CloseHandle(tokenDuplicate);
            return false;
        }

        public void UndoImpersonation()
        {
            impersonationContext.Undo();
        }
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;After referencing my Utilities namespace I was then able to impersonate the account required for uploading:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;if (FileUpload1.HasFile)
{
    ImpersonateUser impersonateUser = new ImpersonateUser();

    if (impersonateUser.ImpersonateValidUser(&amp;quot;userName&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;password&amp;quot;))
    {
        FileUpload1.SaveAs(Server.MapPath(&amp;quot;~/files/fileName.txt&amp;quot;));
        impersonateUser.UndoImpersonation();
    }
    else
    {
        throw new Exception(&amp;quot;Identity impersonation has failed.&amp;quot;);
    }   
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;*The SaveAs method of the FileUpload control requires a root path. Using Server.MapPath will provide the root path of your IIS virtual folder.&lt;/strong&gt;&lt;/p&gt;</description>
      <pubDate>Tue, 27 May 2008 09:01:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:9aea73ef-a3d1-4208-9128-12eb032da707</guid>
      <author>Ryan Baxter</author>
      <link>http://crunchlife.com/articles/2008/05/27/temporary-identity-impersonation-in-asp-net</link>
      <category>Code Snippets</category>
      <category>ASPNET</category>
      <category>dotNET</category>
      <enclosure type="image/jpeg" url="http://crunchlife.com/files/lock.jpg" length="60658"/>
      <trackback:ping>http://crunchlife.com/articles/trackback/66</trackback:ping>
    </item>
    <item>
      <title>System.Drawing.Color Hex Values</title>
      <description>&lt;p&gt;Do you know the &lt;a href="http://en.wikipedia.org/wiki/Hexadecimal" target="_blank"&gt;hexidecimal&lt;/a&gt; value of PapayaWhip? How about BlanchedAlmond? Me either. I&amp;#8217;m not a big fan of the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.drawing.color.aspx" target="_blank"&gt;System.Drawing.Color&lt;/a&gt; structure in the Microsoft .NET Framework. I don&amp;#8217;t think the addition of color names makes good framework design sense. Unless you&amp;#8217;re an Interior Designer; the majority of &lt;a href="http://msdn2.microsoft.com/en-us/library/system.drawing.color_properties.aspx" target="_blank"&gt;these&lt;/a&gt; colors won&amp;#8217;t make sense to you either.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve recently spent time reworking a few design elements of an ASP.NET website. All design related ASP.NET attributes were replaced with &lt;a href="http://en.wikipedia.org/wiki/Cascading_Style_Sheets" target="_blank"&gt;Cascading Style Sheets (CSS)&lt;/a&gt; where applicable. Unfortunately the website was spattered with named colors from the System.Drawing.Color structure. To help replace these named colors with hexadecimal values, I found the following resource extremely helpful.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.opinionatedgeek.com/DotNet/Tools/Colors/default.aspx" target="_blank"&gt;http://www.opinionatedgeek.com/DotNet/Tools/Colors/default.aspx&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 16 Apr 2008 16:29:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:639ae4c8-8229-4ae4-83da-ae27bffdeb7d</guid>
      <author>Ryan Baxter</author>
      <link>http://crunchlife.com/articles/2008/04/16/system-drawing-color-hex-values</link>
      <category>Expect the Unexpected</category>
      <category>ASPNET</category>
      <category>dotNET</category>
      <trackback:ping>http://crunchlife.com/articles/trackback/54</trackback:ping>
    </item>
    <item>
      <title>ASP.NET AJAX Control Toolkit: Transparent Tab Control Images</title>
      <description>&lt;p&gt;I&amp;#8217;ve found a use for the &lt;a href="http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Tabs/Tabs.aspx" target="_blank"&gt;Tab Control&lt;/a&gt; that is included with the &lt;a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=AtlasControlToolkit" target="_blank"&gt;ASP.NET AJAX Control Toolkit&lt;/a&gt;. The control&amp;#8217;s default style is passable for now, but I&amp;#8217;ve grown tired of looking at the white borders surrounding active tabs. If your background is not white, you&amp;#8217;ve probably noticed this too.&lt;/p&gt;

&lt;p&gt;To fix this, I&amp;#8217;ve edited the images and posted them &lt;a href="/files/new_tab_images.zip"&gt;here&lt;/a&gt;. I&amp;#8217;m not sure why the two active tab images were missed when all of the other images have transparent borders. Here are the before and after shots. Please don&amp;#8217;t use these.&lt;/p&gt;

&lt;p&gt;&lt;center&gt;
  &lt;table&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;strong&gt;Before&lt;/strong&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&lt;strong&gt;After&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;img src="/files/tab_before.jpg"&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&lt;img src="/files/tab_after.jpg"&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
&lt;/center&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 10 Apr 2008 08:18:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:627c5337-e4af-4ad3-a252-daee75d87df0</guid>
      <author>Ryan Baxter</author>
      <link>http://crunchlife.com/articles/2008/04/10/asp-net-ajax-control-toolkit-transparent-tab-control-images</link>
      <category>ASPNET</category>
      <category>Ajax</category>
      <category>Oops</category>
      <enclosure type="application/x-zip" url="http://crunchlife.com/files/new_tab_images.zip" length="468"/>
      <trackback:ping>http://crunchlife.com/articles/trackback/53</trackback:ping>
    </item>
    <item>
      <title>Setting Focus in ASP.NET Ajax Pages</title>
      <description>&lt;p&gt;&lt;a href="http://www.amazon.com/gp/product/B000YJ2OJ2?ie=UTF8&amp;amp;tag=crunchlife-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=B000YJ2OJ2"&gt;&lt;img border="0" src="/files/316ZntjzQ2L._AA_SL160_.jpg" class="photo right"&gt;&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=crunchlife-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=B000YJ2OJ2" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;At the new job I&amp;#8217;ve been using a lot of &lt;a href="http://www.asp.net/ajax/" target="_blank"&gt;ASP.NET Ajax&lt;/a&gt; to help ease the transition of users from &lt;a href="http://en.wikipedia.org/wiki/VB6" target="_blank"&gt;VB6&lt;/a&gt; desktop applications to web applications on our company &lt;a href="http://en.wikipedia.org/wiki/Intranet" target="_blank"&gt;intranet&lt;/a&gt;. In doing this, the UpdatePanel has become my new best friend. Albeit charming, my old ASP.NET 2.0 friends were not as impressed.&lt;/p&gt;

&lt;p&gt;With ASP.NET 2.0, came the long-awaited &lt;a href="http://aspnet.4guysfromrolla.com/articles/111506-1.aspx" target="_blank"&gt;Focus&lt;/a&gt; method that allowed developers to set the page focus without having to write any JavaScript. Developers loved it and all was right with the world. That is until ASP.NET Ajax showed up.&lt;/p&gt;

&lt;p&gt;I recently spent way too much time trying set the page focus on a page that contained just a few TextBox controls and an UpdatePanel. My site&amp;#8217;s ScriptManager was located in a MasterPage, but more on that later. My obligatory googling turned up many work arounds, but none as simple as the following:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;// Example

if (Page.IsPostback)
{   
    // Use the GetCurrent method if your ScriptManager is located
    // in a MasterPage. Word.
    ScriptManager.GetCurrent(this.Page).SetFocus(TextBox1);
}
else
{
    // Here is the money.
    AjaxControlToolkit.Utility.SetFocusOnLoad(TextBox2);
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The above example is a two-fer. The ScriptManager&amp;#8217;s SetFocus method is handy, but remember that only one ScriptManager is allowed per page and if you&amp;#8217;ve put your ScriptManager in a MasterPage, then you&amp;#8217;ll need to access it in code using the GetCurrent method of the ScriptManager class. &lt;/p&gt;

&lt;p&gt;Two. The ASP.NET 2.0 UpdatePanel is not the only Ajax control. Download the &lt;a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=AtlasControlToolkit" target="_blank"&gt;ASP.NET Ajax Control Toolkit&lt;/a&gt;. With this toolkit, you&amp;#8217;ll have access to dozens of controls and best of all &amp;#8211; the SetFocusOnLoad method. Located in the Utility class, the SetFocusOnLoad method is the answer to your !Page.IsPostback problems.&lt;/p&gt;</description>
      <pubDate>Mon, 31 Mar 2008 15:24:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:a059a73f-ed79-457f-9df5-24ab32e0fdd7</guid>
      <author>Ryan Baxter</author>
      <link>http://crunchlife.com/articles/2008/03/31/setting-focus-in-asp-net-ajax-pages</link>
      <category>Code Snippets</category>
      <category>ASPNET</category>
      <category>Ajax</category>
      <category>Oops</category>
      <enclosure type="image/jpeg" url="http://crunchlife.com/files/316ZntjzQ2L._AA_SL160_.jpg" length="9085"/>
      <trackback:ping>http://crunchlife.com/articles/trackback/52</trackback:ping>
    </item>
    <item>
      <title>Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login'</title>
      <description>&lt;p&gt;&lt;img src="/files/brick.jpg" class="right"&gt;Just a quick fix.  If you&amp;#8217;re experiencing the error message, &lt;strong&gt;Cannot convert type &amp;#8216;ASP.login_aspx&amp;#8217; to &amp;#8216;System.Web.UI.WebControl&lt;/strong&gt;, try renaming your page from Login.aspx to something else.&lt;/p&gt;

&lt;p&gt;I ran across this earlier this morning when attempting to deploy an ASP.NET 2.0 WebSite project. My code worked great locally (isn&amp;#8217;t that always the case). I haven&amp;#8217;t had time to really dig into why this happens, but maybe someone else can provide an answer.&lt;/p&gt;</description>
      <pubDate>Thu, 28 Feb 2008 10:38:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:dfb541d1-36a9-49d2-ae21-d2f6078645c1</guid>
      <author>Ryan Baxter</author>
      <link>http://crunchlife.com/articles/2008/02/28/cannot-convert-type-asp-login_aspx-to-system-web-ui-webcontrols-login</link>
      <category>ASPNET</category>
      <category>Oops</category>
      <enclosure type="image/jpeg" url="http://crunchlife.com/files/brick.jpg" length="46540"/>
      <trackback:ping>http://crunchlife.com/articles/trackback/50</trackback:ping>
    </item>
    <item>
      <title>Expect the Unexpected: bool IsInRole(string role)</title>
      <description>&lt;p&gt;Running some tests yesterday, I was alarmed by an Exception that read, &amp;#8220;The trust relationship between the primary domain and the trusted domain failed.&amp;#8221;  What?!?  This code worked a few weeks ago!  The method in question called Page.User.IsInRole(&amp;#8220;DomainName\RoleName&amp;#8221;) to determine if a user was assigned to an administrator&amp;#8217;s role.  bool IsAdministrator().  Simple and efficient.  Why is this happening?!?&lt;/p&gt;

&lt;p&gt;&lt;img src="/files/IsInRole_Error.png" alt="IsInRole"/&gt;&lt;/p&gt;

&lt;p&gt;In short, the role that I was supplying Page.User.IsInRole with contained a typo.  What is interesting is the results of my test case found below.  Pay attention to the method signatures and their outcome.&lt;/p&gt;

&lt;p&gt;Page.User.IsInRole(&amp;#8220;DomainName\RoleName&amp;#8221;) returns true&lt;br /&gt;
Page.User.IsInRole(&amp;#8220;RoleName&amp;#8221;) returns true&lt;/p&gt;

&lt;p&gt;Page.User.IsInRole(&amp;#8220;DomainName\TypoRoleName&amp;#8221;) returns false&lt;/p&gt;

&lt;p&gt;But&amp;#8230;&lt;/p&gt;

&lt;p&gt;Page.User.IsInRole(&amp;#8220;TypoRoleName&amp;#8221;) throws the Exception&lt;/p&gt;

&lt;p&gt;Huh?&lt;/p&gt;

&lt;p&gt;I haven&amp;#8217;t had time to dig further into this, but I&amp;#8217;d definitely be interested in hearing some opinions.&lt;/p&gt;</description>
      <pubDate>Mon, 09 Jul 2007 19:34:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:5abe8be8-b46a-46c6-846d-ee10ec979f46</guid>
      <author>Ryan Baxter</author>
      <link>http://crunchlife.com/articles/2007/07/09/expect-the-unexpected-bool-isinrole-string-role</link>
      <category>Expect the Unexpected</category>
      <category>ASPNET</category>
    </item>
  </channel>
</rss>
