<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: ASP.NET MVC Using Forms Authentication With LDAP</title>
	<atom:link href="http://www.cmjackson.net/2009/10/23/asp-net-mvc-using-forms-authentication-with-ldap/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cmjackson.net/2009/10/23/asp-net-mvc-using-forms-authentication-with-ldap/</link>
	<description>Web Design, Programming, Tutorials</description>
	<lastBuildDate>Wed, 21 Jul 2010 19:57:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Chris Jackson</title>
		<link>http://www.cmjackson.net/2009/10/23/asp-net-mvc-using-forms-authentication-with-ldap/comment-page-1/#comment-2129</link>
		<dc:creator>Chris Jackson</dc:creator>
		<pubDate>Mon, 07 Jun 2010 16:06:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.cmjackson.net/?p=262#comment-2129</guid>
		<description>@JeffKirby
The Authorize attribute should work because the code in the global.asax is creating a new GenericPrincipal using the list of groups stored in the cookie and then passing it into the user context.

The group names should match those you create in Active Directory.  I have noticed that the built-in groups do not show in this list.  I have had to use my own custom groups. 

If there are spaces in the group names, that may be the problem. Maybe the IsInRole trims the group passed into it and the Authorize atribute does not? Not sure.

If you found another way that you prefer, that&#039;s great!  The nice thing about programming is there&#039;s about a million ways to do something and you get to be creative in coming up with your answer.</description>
		<content:encoded><![CDATA[<p>@JeffKirby<br />
The Authorize attribute should work because the code in the global.asax is creating a new GenericPrincipal using the list of groups stored in the cookie and then passing it into the user context.</p>
<p>The group names should match those you create in Active Directory.  I have noticed that the built-in groups do not show in this list.  I have had to use my own custom groups. </p>
<p>If there are spaces in the group names, that may be the problem. Maybe the IsInRole trims the group passed into it and the Authorize atribute does not? Not sure.</p>
<p>If you found another way that you prefer, that&#8217;s great!  The nice thing about programming is there&#8217;s about a million ways to do something and you get to be creative in coming up with your answer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JeffKirby</title>
		<link>http://www.cmjackson.net/2009/10/23/asp-net-mvc-using-forms-authentication-with-ldap/comment-page-1/#comment-2125</link>
		<dc:creator>JeffKirby</dc:creator>
		<pubDate>Mon, 07 Jun 2010 01:16:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.cmjackson.net/?p=262#comment-2125</guid>
		<description>I should also mention that negates the need to mess with the user context at all.</description>
		<content:encoded><![CDATA[<p>I should also mention that negates the need to mess with the user context at all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JeffKirby</title>
		<link>http://www.cmjackson.net/2009/10/23/asp-net-mvc-using-forms-authentication-with-ldap/comment-page-1/#comment-2124</link>
		<dc:creator>JeffKirby</dc:creator>
		<pubDate>Mon, 07 Jun 2010 01:15:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.cmjackson.net/?p=262#comment-2124</guid>
		<description>@Chris
The reason I mentioned the getRolesForUser is that the Authorize(Roles: ) thing doesn&#039;t work and I used it to see what was there. Maybe that was the wrong path to go down.
I can make it work,by creating Roles in the role manager, and then in the global.asx method, add the user to the role like this 

string[] groups = authTicket.UserData.ToString().Split(&#039;&#124;&#039;);

                        foreach (string group in groups)
                        {
                            if (Roles.RoleExists(group))
                            {
                                if (!User.IsInRole(group))
                                {
                                    Roles.AddUserToRole(authTicket.Name, group);
                                }
                            }
                        }

Its quick and dirty and works fine :). Then everything works.</description>
		<content:encoded><![CDATA[<p>@Chris<br />
The reason I mentioned the getRolesForUser is that the Authorize(Roles: ) thing doesn&#8217;t work and I used it to see what was there. Maybe that was the wrong path to go down.<br />
I can make it work,by creating Roles in the role manager, and then in the global.asx method, add the user to the role like this </p>
<p>string[] groups = authTicket.UserData.ToString().Split(&#8216;|&#8217;);</p>
<p>                        foreach (string group in groups)<br />
                        {<br />
                            if (Roles.RoleExists(group))<br />
                            {<br />
                                if (!User.IsInRole(group))<br />
                                {<br />
                                    Roles.AddUserToRole(authTicket.Name, group);<br />
                                }<br />
                            }<br />
                        }</p>
<p>Its quick and dirty and works fine <img src='http://www.cmjackson.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Then everything works.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Jackson</title>
		<link>http://www.cmjackson.net/2009/10/23/asp-net-mvc-using-forms-authentication-with-ldap/comment-page-1/#comment-2058</link>
		<dc:creator>Chris Jackson</dc:creator>
		<pubDate>Fri, 14 May 2010 13:01:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.cmjackson.net/?p=262#comment-2058</guid>
		<description>@JeffKirby
I&#039;ve not used the roles.getRolesForUser method, but instead used the following attribute for checking the role within a controller action:

&lt; Authorize(Roles:=&quot;Group1,Group2,Group3&quot;) &gt; _

...and used the following for checking a role within a user control:

&lt;% If (Context.User.IsInRole(&quot;Group1&quot;)) Then %&gt;

This code was setup on MVC1.0 using VS2008. I haven&#039;t tried running this on the upgraded versions, so I&#039;m not sure if something will break by using them, but would assume that it would work.

If you need to use the getRolesForUser function for some reason, you might download the MVC source code and see if you can find what exactly that function is doing.</description>
		<content:encoded><![CDATA[<p>@JeffKirby<br />
I&#8217;ve not used the roles.getRolesForUser method, but instead used the following attribute for checking the role within a controller action:</p>
<p>< Authorize(Roles:="Group1,Group2,Group3") > _</p>
<p>&#8230;and used the following for checking a role within a user control:</p>
<p>< % If (Context.User.IsInRole("Group1")) Then %></p>
<p>This code was setup on MVC1.0 using VS2008. I haven&#8217;t tried running this on the upgraded versions, so I&#8217;m not sure if something will break by using them, but would assume that it would work.</p>
<p>If you need to use the getRolesForUser function for some reason, you might download the MVC source code and see if you can find what exactly that function is doing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JeffKirby</title>
		<link>http://www.cmjackson.net/2009/10/23/asp-net-mvc-using-forms-authentication-with-ldap/comment-page-1/#comment-1969</link>
		<dc:creator>JeffKirby</dc:creator>
		<pubDate>Thu, 29 Apr 2010 00:39:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.cmjackson.net/?p=262#comment-1969</guid>
		<description>Hey Chris,

I&#039;ve translated this to C# and it all looks to be working, right up until I try and check the roles ( roles.getRolesForUser ) or look in the debugger on the User object in a page ( in this case the LogOnUserControl ). The Roles are empty. The Global.asax method is however populating the Identity correctly according to the debugger. I have Role Manager on ( should I not? ) but thats about all I&#039;ve set ( using MVC2 default kit under VS2010 )</description>
		<content:encoded><![CDATA[<p>Hey Chris,</p>
<p>I&#8217;ve translated this to C# and it all looks to be working, right up until I try and check the roles ( roles.getRolesForUser ) or look in the debugger on the User object in a page ( in this case the LogOnUserControl ). The Roles are empty. The Global.asax method is however populating the Identity correctly according to the debugger. I have Role Manager on ( should I not? ) but thats about all I&#8217;ve set ( using MVC2 default kit under VS2010 )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Jackson</title>
		<link>http://www.cmjackson.net/2009/10/23/asp-net-mvc-using-forms-authentication-with-ldap/comment-page-1/#comment-1734</link>
		<dc:creator>Chris Jackson</dc:creator>
		<pubDate>Sat, 20 Mar 2010 22:38:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.cmjackson.net/?p=262#comment-1734</guid>
		<description>If you want to have users auto login, you can use Windows authentication instead of Forms authentication. In the web config, use &lt;authentication mode=&quot;Windows&quot;&gt;.  This will set the authenticated user to the user logged into the client computer.  This works well for sites such as a company intranet.  If the user cannot be authenticated, then a login box will ask them for a user/password.

If you want to use both authentication methods at the same time, I&#039;m not sure that is possible.</description>
		<content:encoded><![CDATA[<p>If you want to have users auto login, you can use Windows authentication instead of Forms authentication. In the web config, use <authentication mode="Windows">.  This will set the authenticated user to the user logged into the client computer.  This works well for sites such as a company intranet.  If the user cannot be authenticated, then a login box will ask them for a user/password.</p>
<p>If you want to use both authentication methods at the same time, I&#8217;m not sure that is possible.</authentication></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gonzalo</title>
		<link>http://www.cmjackson.net/2009/10/23/asp-net-mvc-using-forms-authentication-with-ldap/comment-page-1/#comment-1721</link>
		<dc:creator>Gonzalo</dc:creator>
		<pubDate>Wed, 17 Mar 2010 16:12:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.cmjackson.net/?p=262#comment-1721</guid>
		<description>Thanks for this article! It&#039;s really helpfull.
Maybe you can help me with this: I&#039;m using your code in a project, I will have users accesing from outside the domain and others from PCs within the domain.
For the PCs in the domain, I want to skip the login process and get the current user to automatically log him in. How can I do this?</description>
		<content:encoded><![CDATA[<p>Thanks for this article! It&#8217;s really helpfull.<br />
Maybe you can help me with this: I&#8217;m using your code in a project, I will have users accesing from outside the domain and others from PCs within the domain.<br />
For the PCs in the domain, I want to skip the login process and get the current user to automatically log him in. How can I do this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Jackson</title>
		<link>http://www.cmjackson.net/2009/10/23/asp-net-mvc-using-forms-authentication-with-ldap/comment-page-1/#comment-1222</link>
		<dc:creator>Chris Jackson</dc:creator>
		<pubDate>Tue, 22 Dec 2009 22:48:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.cmjackson.net/?p=262#comment-1222</guid>
		<description>You could add the flag properties to your user object, then during the Authenticate method of the userRepository, check for the expired password and create a user object with the appropriate flags.  In the account controller, you&#039;d have to modify the if block after the user is authenticated...   You would want to check if the user = nothing, redirect to signon screen with errors; user exists but flags are set, redirect to password change screen; otherwise user is valid and redirect to desired URL.  I&#039;m not sure on the specifics for checking LDAP for expired passwords.  I&#039;m sure you can find many resources about it on google.</description>
		<content:encoded><![CDATA[<p>You could add the flag properties to your user object, then during the Authenticate method of the userRepository, check for the expired password and create a user object with the appropriate flags.  In the account controller, you&#8217;d have to modify the if block after the user is authenticated&#8230;   You would want to check if the user = nothing, redirect to signon screen with errors; user exists but flags are set, redirect to password change screen; otherwise user is valid and redirect to desired URL.  I&#8217;m not sure on the specifics for checking LDAP for expired passwords.  I&#8217;m sure you can find many resources about it on google.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vince</title>
		<link>http://www.cmjackson.net/2009/10/23/asp-net-mvc-using-forms-authentication-with-ldap/comment-page-1/#comment-1160</link>
		<dc:creator>Vince</dc:creator>
		<pubDate>Mon, 14 Dec 2009 20:37:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.cmjackson.net/?p=262#comment-1160</guid>
		<description>Is there a way to add useraccountcontrl flags? For example how would I be able to redirect users who have the password expired to another link where they can reset the password.</description>
		<content:encoded><![CDATA[<p>Is there a way to add useraccountcontrl flags? For example how would I be able to redirect users who have the password expired to another link where they can reset the password.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Jackson</title>
		<link>http://www.cmjackson.net/2009/10/23/asp-net-mvc-using-forms-authentication-with-ldap/comment-page-1/#comment-1159</link>
		<dc:creator>Chris Jackson</dc:creator>
		<pubDate>Mon, 14 Dec 2009 13:36:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.cmjackson.net/?p=262#comment-1159</guid>
		<description>The FormsAuthentication class writes a cookie with the user&#039;s name and list of groups.  The code in the Global.asax file then loads the data from that cookie into the session&#039;s current user for each request.

Then, if you want to use the Data.User object, you can do a lookup using the LDAP class on the user&#039;s name read in from the cookie (which is now in the session&#039;s current user).

There may be other ways to do this, but this was one way I found that worked with the &lt;Authorize&gt; attributes and Active Directory groups.</description>
		<content:encoded><![CDATA[<p>The FormsAuthentication class writes a cookie with the user&#8217;s name and list of groups.  The code in the Global.asax file then loads the data from that cookie into the session&#8217;s current user for each request.</p>
<p>Then, if you want to use the Data.User object, you can do a lookup using the LDAP class on the user&#8217;s name read in from the cookie (which is now in the session&#8217;s current user).</p>
<p>There may be other ways to do this, but this was one way I found that worked with the <authorize> attributes and Active Directory groups.</authorize></p>
]]></content:encoded>
	</item>
</channel>
</rss>
