<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Moving the Curve &#187; asp.net</title>
	<atom:link href="http://www.stevideter.com/category/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stevideter.com</link>
	<description>Technology, code, and thoughts by Stevi Deter</description>
	<lastBuildDate>Fri, 16 Apr 2010 17:01:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Picking the right .NET Framework Version with Specific Reference</title>
		<link>http://www.stevideter.com/2008/08/14/picking-the-right-net-framework-version-with-specific-reference/</link>
		<comments>http://www.stevideter.com/2008/08/14/picking-the-right-net-framework-version-with-specific-reference/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 17:38:02 +0000</pubDate>
		<dc:creator>stevi</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[csharp]]></category>

		<guid isPermaLink="false">http://www.stevideter.com/?p=26</guid>
		<description><![CDATA[This morning I needed to work on a long-standing ASP.NET web application project. I haven&#8217;t had to run it locally for quite a while. I updated my source from TFS, cleaned and built the solution, and started the project in debug mode. After logging in, I went to a page, and was suddenly staring at [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This morning I needed to work on a long-standing ASP.NET web application project. I haven&#8217;t had to run it locally for quite a while. I updated my source from TFS, cleaned and built the solution, and started the project in debug mode. After logging in, I went to a page, and was suddenly staring at an unexpected and confusing exception:</p>
<pre>The base class includes the field 'ScriptManager1',
but its type (System.Web.UI.ScriptManager)
is not compatible with the type of control
(System.Web.UI.ScriptManager).</pre>
<p>
I put aside the surprise that a type was not compatible with itself, and checked the source control history. The specific page hadn&#8217;t been changed since the last time I&#8217;d tried it. I know the project is under active development, including a recent deployment of the latest version at the client site, so I had ever reason to believe the build should work. </p>
<p>Before sending a panicked email to my team, I did a quick Google search. I found a couple links of similar people with this problem in VS2008, but I&#8217;m still running VS2005. </p>
<p>I realized, however, that I had installed Framework versions 3.0 and 3.5 since I had last had to work on this project. I went to the project references, and checked that for System.Web.Extensions, and noticed that &#8220;Specific Reference&#8221; was set to false. I set this to true, rebuilt the project, and started the debugger again. </p>
<p>This time, success! The page displayed as expected. </p>
<p>What problems have you encountered from having multiple .NET Frameworks installed? </p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.stevideter.com/2008/08/14/picking-the-right-net-framework-version-with-specific-reference/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using two Membership Providers for ASP.NET logins</title>
		<link>http://www.stevideter.com/2008/03/20/using-two-membership-providers-for-aspnet-logins/</link>
		<comments>http://www.stevideter.com/2008/03/20/using-two-membership-providers-for-aspnet-logins/#comments</comments>
		<pubDate>Thu, 20 Mar 2008 23:57:02 +0000</pubDate>
		<dc:creator>stevi</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[membership]]></category>
		<category><![CDATA[membership framework]]></category>
		<category><![CDATA[roles]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.stevideter.com/2008/03/20/using-two-membership-providers-for-aspnet-logins/</guid>
		<description><![CDATA[I quite like the Microsoft Membership Framework for handling membership roles, authentication, and security resources in ASP.NET applications. It&#8217;s easy to create the initial user login and management framework for a new application, then swap in a more sophisticated Provider as needed. For my current project, we have a new requirement to allow logins against [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>I quite like the Microsoft Membership Framework for handling <a href="http://weblogs.asp.net/scottgu/archive/2006/02/24/ASP.NET-2.0-Membership_2C00_-Roles_2C00_-Forms-Authentication_2C00_-and-Security-Resources-.aspx" title="ScottGu's list of links about Membership in .NET 2.0" target="_blank">membership roles, authentication, and security resources</a> in ASP.NET applications. It&#8217;s easy to create the initial user login and management framework for a new application, then swap in a more sophisticated Provider as needed.</p>
<p>For my current project, we have a new requirement to allow logins against multiple user stores. The existing application validates against an Active Directory store. But for a subset of users, there is a need to check if they are in a SQL Server database and allow them to login while they wait for their Active Directory setup to complete. This SQL Server also contains a secondary set of roles that will be relevant for any user that is in the SQL Server user store, regardless of whether they were validated via AD or the SQL Server.</p>
<p>The first step I took was to figure out the easiest way to have two separate providers to validate the user. You can configure as many membership providers as you want in the web.config for your application, but you choose a default provider as part of the setup. If you use the standard Login control, it will only check against that default provider.</p>
<p>In order to change that behavior, I overrode the Login.Authenticate event for my Login control. The method looks a little like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Login1_Authenticate<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, AuthenticateEventArgs e<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #FF0000;">bool</span> foundUser <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
        List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span> roles <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        roles.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;GeneralUser&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">// this will call the default MembershipProvider</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>Membership.<span style="color: #0000FF;">Provider</span>.<span style="color: #0000FF;">ValidateUser</span><span style="color: #000000;">&#40;</span>LoginBox.<span style="color: #0000FF;">UserName</span>, LoginBox.<span style="color: #0000FF;">Password</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            foundUser <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// do any additional lookups for this type of user (Default MembershipProvider) here</span>
        <span style="color: #000000;">&#125;</span> <span style="color: #008080; font-style: italic;">// otherwise, explicitly call secondary provider</span>
        <span style="color: #0600FF;">else</span> <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>
            Membership.<span style="color: #0000FF;">Providers</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;SecondarySqlMembershipProvider&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ValidateUser</span><span style="color: #000000;">&#40;</span>LoginBox.<span style="color: #0000FF;">UserName</span>,
                                                                                LoginBox.<span style="color: #0000FF;">Password</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            foundUser <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
            roles.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;SecondaryUser&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// do any additional lookups relevant to this type of user</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>foundUser<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Session<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;UserId&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> LoginBox.<span style="color: #0000FF;">UserName</span><span style="color: #008000;">;</span>
            Session<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Groups&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> roles<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        e.<span style="color: #0000FF;">Authenticated</span> <span style="color: #008000;">=</span> foundUser<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span></pre></div></div>

<p>I didn&#8217;t need to modify the Authentication Ticket or cookie, so I could rely on the Membership Framework to handle the rest. If I need to add additional information, I can do it in the commented spots to correctly handle the type of user I care about.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.stevideter.com/2008/03/20/using-two-membership-providers-for-aspnet-logins/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Role aware ASP.NET web controls</title>
		<link>http://www.stevideter.com/2008/03/12/role-aware-aspnet-web-controls/</link>
		<comments>http://www.stevideter.com/2008/03/12/role-aware-aspnet-web-controls/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 01:09:00 +0000</pubDate>
		<dc:creator>stevi</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[role]]></category>
		<category><![CDATA[webcontrol]]></category>

		<guid isPermaLink="false">http://www.stevideter.com/2008/03/12/role-aware-aspnet-web-controls/</guid>
		<description><![CDATA[A common feature I&#8217;ve found necessary for web applications is role-based security at the field level. For example, I may have a form that allows editing a user&#8217;s information. The requirements may include the rule that only certain types (roles) may edit certain fields. This can be accomplished in myriad ways. You can create a [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>A common feature I&#8217;ve found necessary for web applications is role-based security at the field level. For example, I may have a form that allows editing a user&#8217;s information. The requirements may include the rule that only certain types (roles) may edit certain fields.</p>
<p>This can be accomplished in myriad ways. You can create a different form per role, and direct the user to the appropriate form. Or you can put specific logic around each relevant field to show, enable, or hide each field.</p>
<p>Both these routes can lead to a lot of extra coding, and even more maintenance. I&#8217;d like to be able to tell each affected field to display itself correctly based on the user&#8217;s role.</p>
<p>The Microsoft.NET Framework 2.0 introduced the Membership and Roles framework and the Microsoft Provider Model, which gives us an API-based way to  interface with users and roles. If you use a RoleManager (either one of the defaults provided or your own custom implementation), the following code gives an example of how you can extend the existing WebControls to render themselves based on a current user&#8217;s roles.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI.WebControls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.ComponentModel</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">namespace</span> RoleAwareServerControls
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #008080; font-style: italic;">/// Role Aware Text Box. Will only render as Enabled if user is</span>
    <span style="color: #008080; font-style: italic;">/// in the in the RoleName.</span>
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #000000;">&#91;</span>DefaultProperty<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Text&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span>ToolboxData<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;{0}:RoleAwareTextBox runat=server RoleName=user&gt;&lt;/{0}:RoleAwareTextBox&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> RoleAwareTextBox <span style="color: #008000;">:</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UI</span>.<span style="color: #0000FF;">WebControls</span></span>.<span style="color: #0000FF;">TextBox</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">bool</span> visibleIfUnauthorized<span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">/// if user is not in role, should the field be displayed at all?</span>
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> VisibleIfUnauthorized
        <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> visibleIfUnauthorized<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span> visibleIfUnauthorized <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">String</span> roleName<span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">/// if user is in this role, enable this field, else not</span>
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">String</span> RoleName
        <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> roleName<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span> roleName <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">/// determine if TextBox should be Enabled or Visible</span>
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">///An EventArgs</span>
       <span style="color: #008080; font-style: italic;">/// that contains the event data.</span>
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnPreRender<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnPreRender</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// assume normal display if RoleName not set</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>roleName<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                Enabled <span style="color: #008000;">=</span>
                    <span style="color: #000000;">&#40;</span>Page.<span style="color: #0000FF;">User</span>.<span style="color: #0000FF;">Identity</span>.<span style="color: #0000FF;">IsAuthenticated</span> <span style="color: #008000;">&amp;&amp;</span> Page.<span style="color: #0000FF;">User</span>.<span style="color: #0000FF;">IsInRole</span><span style="color: #000000;">&#40;</span>roleName<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                Visible <span style="color: #008000;">=</span> Enabled <span style="color: #008000;">?</span> <span style="color: #0600FF;">true</span> <span style="color: #008000;">:</span> visibleIfUnauthorized<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>To use the new web control, register it with your page (or for the whole application in your web.config) and add it to the page:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;%@ Page Language=&quot;C#&quot; MasterPageFile=&quot;~/Site.master&quot; 
    AutoEventWireup=&quot;true&quot; CodeFile=&quot;Default.aspx.cs&quot; 
    Inherits=&quot;_Default&quot; Theme=&quot;Default&quot; %&gt;
&lt;%@ Register TagPrefix=&quot;rasc&quot; Namespace=&quot;RoleAwareServerControls&quot; %&gt;
&lt;body&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
        &lt;rasc:RoleAwareTextBox runat=&quot;server&quot; ID=&quot;textBox&quot;
            RoleName=&quot;administrator&quot; VisibleIfUnauthorized=&quot;true&quot; &gt;
            Hi, administrator&lt;/rasc:RoleAwareTextBox&gt;
    &lt;/form&gt;
&lt;/body&gt;</pre></div></div>



<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.stevideter.com/2008/03/12/role-aware-aspnet-web-controls/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
