<?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">Ben Hickman's Blog</title><subtitle type="html">.NET Ramblings</subtitle><id>http://weblogs.asp.net/bhickman/atom.aspx</id><link rel="alternate" type="text/html" href="http://weblogs.asp.net/bhickman/default.aspx" /><link rel="self" type="application/atom+xml" href="http://weblogs.asp.net/bhickman/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20510.895">Community Server</generator><updated>2003-02-07T12:13:00Z</updated><entry><title>Precompiling ASP.NET</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/bhickman/archive/2003/02/10/2183.aspx" /><id>http://weblogs.asp.net/bhickman/archive/2003/02/10/2183.aspx</id><published>2003-02-10T19:04:00Z</published><updated>2003-02-10T19:04:00Z</updated><content type="html">&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&lt;EM&gt;With this assembly you can easily achieve to precompile your whole ASP.NET web applications - including .aspx, .asmx, .ascx and .ashx files - without having to manually touch every single resource.&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;[&lt;A href="http://dotnetweblogs.com/Cweyer/archive/02072003.aspx#2013"&gt;Christian Weyer: Web Services &amp;amp; .NET&lt;/A&gt;]&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;This is a nice solution: use&amp;nbsp;the Init method of an HttpModule to precompile everything on app startup.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2183" width="1" height="1"&gt;</content><author><name>fleenj</name><uri>http://weblogs.asp.net/members/fleenj.aspx</uri></author></entry><entry><title>VSIP</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/bhickman/archive/2003/02/10/2180.aspx" /><id>http://weblogs.asp.net/bhickman/archive/2003/02/10/2180.aspx</id><published>2003-02-10T18:42:00Z</published><updated>2003-02-10T18:42:00Z</updated><content type="html">&lt;P&gt;&lt;A href="http://dotnetweblogs.com/sgentile/"&gt;Sam&lt;/A&gt; &lt;A href="http://dotnetweblogs.com/sgentile/archive/02082003.aspx#2045"&gt;writes&lt;/A&gt; about &lt;A href="http://msdn.microsoft.com/vstudio/vsip/default.asp"&gt;VSIP&lt;/A&gt;. I just finished a VSIP project for a customer and agree it's a battle. All the typical suspects: doc errors, whole sections undocumented, and light on introductory material.&lt;/P&gt;
&lt;P&gt;I was mostly building Tool Windows and found it most helpful to start with the AIWTool sample project. This allowed me to create ActiveX controls separate from VSIP and them embed them in a Tool Window in VS.NET. &lt;/P&gt;
&lt;P&gt;My main stumbling block right now is integrating with Server Explorer. It's undocumented and I haven't figured it all out yet.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2180" width="1" height="1"&gt;</content><author><name>fleenj</name><uri>http://weblogs.asp.net/members/fleenj.aspx</uri></author></entry><entry><title>Thanks Scott</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/bhickman/archive/2003/02/10/2179.aspx" /><id>http://weblogs.asp.net/bhickman/archive/2003/02/10/2179.aspx</id><published>2003-02-10T18:41:00Z</published><updated>2003-02-10T18:41:00Z</updated><content type="html">Thanks &lt;A href="http://radio.weblogs.com/0106747/2003/02/07.html"&gt;Scott&lt;/A&gt;, for the intro. Who knew I had a flourish?&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2179" width="1" height="1"&gt;</content><author><name>fleenj</name><uri>http://weblogs.asp.net/members/fleenj.aspx</uri></author></entry><entry><title>Custom roles for WindowsPrincipals in ASP.NET</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/bhickman/archive/2003/02/07/2018.aspx" /><id>http://weblogs.asp.net/bhickman/archive/2003/02/07/2018.aspx</id><published>2003-02-07T21:27:00Z</published><updated>2003-02-07T21:27:00Z</updated><content type="html">&lt;P&gt;I continue to be pleased with the many plug-points within ASP.NET. Recently, I had a student with an interesting ASP.NET security challenge. He wanted to use&amp;nbsp;integrated windows authentication, but wanted to&amp;nbsp;assign custom roles for the&amp;nbsp;windows principals. He&amp;nbsp;was building an intranet site.&amp;nbsp;He needed a set of roles that didn't map to any existing Windows groups and he couldn't get the network&amp;nbsp;admins to add them (and keep them updated).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It turns out this is quite easy with ASP.NET. First, create a new class to hold the roles (thankfully, WindowsPrincipal isn't sealed!):&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;&lt;FONT face="Lucida Console"&gt;using System.Collections;&lt;BR&gt;using System.Security.Principal;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Console"&gt;public class CustomPrincipal : WindowsPrincipal&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private ArrayList m_Roles;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Console"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public CustomPrincipal(WindowsIdentity identity): base(identity)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_Roles = new ArrayList?();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Console"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override bool IsInRole(string role)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // May&amp;nbsp;or may not make sense to check&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // WindowsPrincipal role if membership fails&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // for the local list.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (m_Roles.Contains(role))&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; return true;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&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; return base.IsInRole(role);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Console"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void AddRole(string role)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_Roles.Add(role);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Now, add the following code to Global.asax.cs&amp;nbsp;to hook into the Windows authentication process in ASP.NET and setup the new CustomPrincipal and its roles:&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;&lt;FONT face="Lucida Console"&gt;protected void WindowsAuthentication_OnAuthenticate(object sender,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WindowsAuthenticationEventArgs e)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (e.Identity != null &amp;amp;&amp;amp; e.Identity.IsAuthenticated)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CustomPrincipal p = new CustomPrincipal((WindowsIdentity)e.Identity);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Console"&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;&amp;nbsp;&amp;nbsp; // Add the appropriate roles, e.g. read&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // them out of a database.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.AddRole("CustomRole");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HttpContext.Current.User = p;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then, just use the normal ASP.NET authorization services. You can write code that uses Page.User.IsInRole() or using Web.config, e.g.:&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;&lt;FONT face="Lucida Console"&gt;&amp;lt;authentication mode="Windows" /&amp;gt;&lt;BR&gt;&amp;lt;identity impersonate="true" &amp;gt;&lt;BR&gt;&amp;lt;authorization&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;allow roles="BUILTIN\Administrators" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;allow roles="CustomRole" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;deny users="*" /&amp;gt;&lt;BR&gt;&amp;lt;/authorization&amp;gt;&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2018" width="1" height="1"&gt;</content><author><name>fleenj</name><uri>http://weblogs.asp.net/members/fleenj.aspx</uri></author></entry><entry><title>And Begin</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/bhickman/archive/2003/02/07/2009.aspx" /><id>http://weblogs.asp.net/bhickman/archive/2003/02/07/2009.aspx</id><published>2003-02-07T20:13:00Z</published><updated>2003-02-07T20:13:00Z</updated><content type="html">Hello weblog&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2009" width="1" height="1"&gt;</content><author><name>fleenj</name><uri>http://weblogs.asp.net/members/fleenj.aspx</uri></author></entry></feed>
