<?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: Securing Your Controller Actions (The .NET Framework Way)</title>
	<atom:link href="http://www.coderjournal.com/index.php/2008/03/securing-mvc-controller-actions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/</link>
	<description>while(!(succeed = try()));</description>
	<pubDate>Tue, 06 Jan 2009 13:50:03 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Matt Dwyer</title>
		<link>http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/comment-page-1/#comment-15268</link>
		<dc:creator>Matt Dwyer</dc:creator>
		<pubDate>Mon, 15 Sep 2008 17:23:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/#comment-15268</guid>
		<description>Obviously I have to respect your opinion on that, but I just don't see it, consider your quote:

&#62;&#62;&#62;My only guess is that he just wanted to re-invent something that is already built in to the framework using his own code&#60;&#60;&#60;

Who hasn't reinvented something in a/the framework with their own code at some point?</description>
		<content:encoded><![CDATA[<p>Obviously I have to respect your opinion on that, but I just don&#8217;t see it, consider your quote:</p>
<p>&gt;&gt;&gt;My only guess is that he just wanted to re-invent something that is already built in to the framework using his own code&lt;&lt;&lt;</p>
<p>Who hasn&#8217;t reinvented something in a/the framework with their own code at some point?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Berardi</title>
		<link>http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/comment-page-1/#comment-15266</link>
		<dc:creator>Nick Berardi</dc:creator>
		<pubDate>Mon, 15 Sep 2008 17:03:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/#comment-15266</guid>
		<description>Matt, Everything else left aside, I was in the wrong on this.</description>
		<content:encoded><![CDATA[<p>Matt, Everything else left aside, I was in the wrong on this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Dwyer</title>
		<link>http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/comment-page-1/#comment-15262</link>
		<dc:creator>Matt Dwyer</dc:creator>
		<pubDate>Mon, 15 Sep 2008 16:00:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/#comment-15262</guid>
		<description>"That was unnecessary. I know you probably didn’t mean to insult, but that’s what it is."

Pretty thin-skinned considering the troll jobs I've seen you do on other people.  I hope some Hawaiian beats you senseless with your sunscreen bottle while you're floundering in the shorebreak trying to get another action pic for your blog.</description>
		<content:encoded><![CDATA[<p>&#8220;That was unnecessary. I know you probably didn’t mean to insult, but that’s what it is.&#8221;</p>
<p>Pretty thin-skinned considering the troll jobs I&#8217;ve seen you do on other people.  I hope some Hawaiian beats you senseless with your sunscreen bottle while you&#8217;re floundering in the shorebreak trying to get another action pic for your blog.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ASP.NET MVC Archived Buzz, Page 1</title>
		<link>http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/comment-page-1/#comment-9867</link>
		<dc:creator>ASP.NET MVC Archived Buzz, Page 1</dc:creator>
		<pubDate>Sun, 13 Jul 2008 15:06:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/#comment-9867</guid>
		<description>[...] [FriendFeed] ASP.NET MVC: Securing Your Controller Actions (The .NET Framework Way) (7/13/2008)Sunday, July 13, 2008 from www.coderjournal.com [...]</description>
		<content:encoded><![CDATA[<p>[...] [FriendFeed] ASP.NET MVC: Securing Your Controller Actions (The .NET Framework Way) (7/13/2008)Sunday, July 13, 2008 from <a href="http://www.coderjournal.com" rel="nofollow">http://www.coderjournal.com</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Berardi</title>
		<link>http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/comment-page-1/#comment-1901</link>
		<dc:creator>Nick Berardi</dc:creator>
		<pubDate>Mon, 17 Mar 2008 16:34:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/#comment-1901</guid>
		<description>Sorry about that I left the following two pieces of code out of SVN.

http://code.google.com/p/coderjournal/source/browse/trunk/ManagedFusion.Web.Mvc/MvcExtensions.cs
http://code.google.com/p/coderjournal/source/browse/trunk/ManagedFusion.Web.Mvc/WebExtensions.cs</description>
		<content:encoded><![CDATA[<p>Sorry about that I left the following two pieces of code out of SVN.</p>
<p><a href="http://code.google.com/p/coderjournal/source/browse/trunk/ManagedFusion.Web.Mvc/MvcExtensions.cs" rel="nofollow">http://code.google.com/p/coderjournal/source/browse/trunk/ManagedFusion.Web.Mvc/MvcExtensions.cs</a><br />
<a href="http://code.google.com/p/coderjournal/source/browse/trunk/ManagedFusion.Web.Mvc/WebExtensions.cs" rel="nofollow">http://code.google.com/p/coderjournal/source/browse/trunk/ManagedFusion.Web.Mvc/WebExtensions.cs</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SubC</title>
		<link>http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/comment-page-1/#comment-1900</link>
		<dc:creator>SubC</dc:creator>
		<pubDate>Mon, 17 Mar 2008 16:17:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/#comment-1900</guid>
		<description>In ExceptionFilterAttribute, OnActionExecuted method used "filterContext.RedirectToAction" which is not supported in the March 2008 MVC release. How should the code be updated to reflect this?

Thanks.</description>
		<content:encoded><![CDATA[<p>In ExceptionFilterAttribute, OnActionExecuted method used &#8220;filterContext.RedirectToAction&#8221; which is not supported in the March 2008 MVC release. How should the code be updated to reflect this?</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Conery</title>
		<link>http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/comment-page-1/#comment-1823</link>
		<dc:creator>Rob Conery</dc:creator>
		<pubDate>Thu, 13 Mar 2008 22:23:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/#comment-1823</guid>
		<description>Nick I wrote a whole post on using PrinciplePermission but didn't post it because I thought it was hitting a tack with a sledgehammer. You have to catch the Exception that is thrown (which some people do in Global.asax) or, like you did, come up with a secondary Filter. This isn't a very good solution in my mind - more code for what payoff? They do the same thing - difference is that you can do more with a filter.

Like redirects - even custom ones. You can also test to see if a user is logged in before tossing an Exception. If you noticed in my sample where I check a Role, I first see if the user's logged in - if they aren't redirect them while appending the proper Return. Your example above throws an Exception - which you'd have to code your way out of to handle properly.

Finally - I'm not sure why you'd suggest the code is "Nasty" because it references FormsAuthentication. This is by way of example of course, so if you wanted to use a different Auth Scheme you could.

&#62;&#62;&#62;My only guess is that he just wanted to re-invent something that is already built in to the framework using his own code&#60;&#60;&#60;

That was unnecessary. I know you probably didn't mean to insult, but that's what it is.</description>
		<content:encoded><![CDATA[<p>Nick I wrote a whole post on using PrinciplePermission but didn&#8217;t post it because I thought it was hitting a tack with a sledgehammer. You have to catch the Exception that is thrown (which some people do in Global.asax) or, like you did, come up with a secondary Filter. This isn&#8217;t a very good solution in my mind - more code for what payoff? They do the same thing - difference is that you can do more with a filter.</p>
<p>Like redirects - even custom ones. You can also test to see if a user is logged in before tossing an Exception. If you noticed in my sample where I check a Role, I first see if the user&#8217;s logged in - if they aren&#8217;t redirect them while appending the proper Return. Your example above throws an Exception - which you&#8217;d have to code your way out of to handle properly.</p>
<p>Finally - I&#8217;m not sure why you&#8217;d suggest the code is &#8220;Nasty&#8221; because it references FormsAuthentication. This is by way of example of course, so if you wanted to use a different Auth Scheme you could.</p>
<p>&gt;&gt;&gt;My only guess is that he just wanted to re-invent something that is already built in to the framework using his own code&lt;&lt;&lt;</p>
<p>That was unnecessary. I know you probably didn&#8217;t mean to insult, but that&#8217;s what it is.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Berardi</title>
		<link>http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/comment-page-1/#comment-1820</link>
		<dc:creator>Nick Berardi</dc:creator>
		<pubDate>Thu, 13 Mar 2008 19:07:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/#comment-1820</guid>
		<description>It is clear that I need to provide a little more insight in to my solution and what I am doing to redirect the user to the login page.  I have created an exception handling attribute that will turn specified exceptions in to specific response codes.  In the case of SecurityException, it gets turned in to a "401 Unauthorized" response code.

Source for ExceptionHandlerAttribute: 
http://code.google.com/p/coderjournal/source/browse/trunk/ManagedFusion.Web.Mvc/ExceptionHandlerAttribute.cs

Also Rob's solution had the nasty habit of assuming everybody was using Form Authentication, if I tried Passport, Windows, or Basic authentication I would be out of luck.  That is why as demonstrated in the example below that set the status code to "401 Unauthorized" and then let whatever authentication module that I am using pick up on the status code and redirect me to a login page for Forms Authentication or pop open a Windows dialog for my credentials or take me off to a Microsoft Password authentication page.

So I would do the following to my method to let the 401 float down to the EndResponse and then let the FormsAuthenticationModule or WindowsAuthenticationModule pick up the HTTP 401 Status Code and do what ever it does depending on what type of authentication you are using.

[PrincipalPermission(SecurityAction.Demand, Name = "SiteAdmin")]
[ExceptionHandler(401, "Unauthorized", typeof(SecurityException)] 
public void RolesAdmin () {  
    RenderView("RolesAdmin");  
}

Or I can redirect them to the correct action depending on the exception that is thrown

[PrincipalPermission(SecurityAction.Demand, Name = "SiteAdmin")]
[ExceptionHandler("Login", "User", typeof(SecurityException)] 
public void RolesAdmin () {  
    RenderView("RolesAdmin");  
}

Thanks,
Nick</description>
		<content:encoded><![CDATA[<p>It is clear that I need to provide a little more insight in to my solution and what I am doing to redirect the user to the login page.  I have created an exception handling attribute that will turn specified exceptions in to specific response codes.  In the case of SecurityException, it gets turned in to a &#8220;401 Unauthorized&#8221; response code.</p>
<p>Source for ExceptionHandlerAttribute:<br />
<a href="http://code.google.com/p/coderjournal/source/browse/trunk/ManagedFusion.Web.Mvc/ExceptionHandlerAttribute.cs" rel="nofollow">http://code.google.com/p/coderjournal/source/browse/trunk/ManagedFusion.Web.Mvc/ExceptionHandlerAttribute.cs</a></p>
<p>Also Rob&#8217;s solution had the nasty habit of assuming everybody was using Form Authentication, if I tried Passport, Windows, or Basic authentication I would be out of luck.  That is why as demonstrated in the example below that set the status code to &#8220;401 Unauthorized&#8221; and then let whatever authentication module that I am using pick up on the status code and redirect me to a login page for Forms Authentication or pop open a Windows dialog for my credentials or take me off to a Microsoft Password authentication page.</p>
<p>So I would do the following to my method to let the 401 float down to the EndResponse and then let the FormsAuthenticationModule or WindowsAuthenticationModule pick up the HTTP 401 Status Code and do what ever it does depending on what type of authentication you are using.</p>
<p>[PrincipalPermission(SecurityAction.Demand, Name = "SiteAdmin")]<br />
[ExceptionHandler(401, "Unauthorized", typeof(SecurityException)]<br />
public void RolesAdmin () {<br />
    RenderView(&#8221;RolesAdmin&#8221;);<br />
}</p>
<p>Or I can redirect them to the correct action depending on the exception that is thrown</p>
<p>[PrincipalPermission(SecurityAction.Demand, Name = "SiteAdmin")]<br />
[ExceptionHandler("Login", "User", typeof(SecurityException)]<br />
public void RolesAdmin () {<br />
    RenderView(&#8221;RolesAdmin&#8221;);<br />
}</p>
<p>Thanks,<br />
Nick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ryan</title>
		<link>http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/comment-page-1/#comment-1817</link>
		<dc:creator>ryan</dc:creator>
		<pubDate>Thu, 13 Mar 2008 18:30:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/#comment-1817</guid>
		<description>So, with your method, is there a way to redirect the user to the login page, and subsequently to the page they were trying to reach after they login?</description>
		<content:encoded><![CDATA[<p>So, with your method, is there a way to redirect the user to the login page, and subsequently to the page they were trying to reach after they login?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse</title>
		<link>http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/comment-page-1/#comment-1815</link>
		<dc:creator>Jesse</dc:creator>
		<pubDate>Thu, 13 Mar 2008 17:36:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/2008/03/securing-mvc-controller-actions/#comment-1815</guid>
		<description>This post would make sense if the PrinicipalPermission actually did what Rob's attributes accomplish.  The PrinicpalPermission will always throw exceptions if the user isn't authenticated or doesn't have the required role.  Rob's attributes redirect an unauthenticated user to the login page. So if your goal is to throw always throw an exception then use the Principal Permission, otherwise if you want to  go down the path of what asp.net does for unauthenticated users then follow the advice in Rob's article.  Nick, maybe you should fully understand what others are trying to accomplish before talking smack.</description>
		<content:encoded><![CDATA[<p>This post would make sense if the PrinicipalPermission actually did what Rob&#8217;s attributes accomplish.  The PrinicpalPermission will always throw exceptions if the user isn&#8217;t authenticated or doesn&#8217;t have the required role.  Rob&#8217;s attributes redirect an unauthenticated user to the login page. So if your goal is to throw always throw an exception then use the Principal Permission, otherwise if you want to  go down the path of what asp.net does for unauthenticated users then follow the advice in Rob&#8217;s article.  Nick, maybe you should fully understand what others are trying to accomplish before talking smack.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
