<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>ASP.NET MVC</title><link>http://forums.asp.net/1146.aspx</link><description>Discussions regarding Model-View-Controller (MVC) support in ASP.NET.  &lt;a href="http://forums.asp.net/1215.aspx"&gt;T4MVC subforum&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Security in asp.net MVC application</title><link>http://forums.asp.net/thread/2238162.aspx</link><pubDate>Mon, 17 Mar 2008 19:05:31 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2238162</guid><dc:creator>MeetNet</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2238162.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2238162</wfw:commentRss><description>&lt;p&gt;The code mentioned in this thread appears to want to deal with HttpContext, but my test framework doesn&amp;#39;t use that, it uses System.Threading.Thread.CurrentPrincipal to house a custom GenericPrincipal that is set for particular tests. I&amp;#39;m taking a harder look at what has to happen here....&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Security in asp.net MVC application</title><link>http://forums.asp.net/thread/2229173.aspx</link><pubDate>Wed, 12 Mar 2008 20:56:03 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2229173</guid><dc:creator>robconery</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2229173.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2229173</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;I wrote this up here:&lt;/p&gt;&lt;p&gt;http://blog.wekeroad.com/2008/03/12/aspnet-mvc-securing-your-controller-actions/&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Security in asp.net MVC application</title><link>http://forums.asp.net/thread/2228714.aspx</link><pubDate>Wed, 12 Mar 2008 17:36:20 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2228714</guid><dc:creator>tgmdbm</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2228714.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2228714</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;override OnActionExecuted, if no error occured then Exception will be null, if you handle the exception (by rendering an error view) set ExceptionHandled to true.&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Security in asp.net MVC application</title><link>http://forums.asp.net/thread/2228688.aspx</link><pubDate>Wed, 12 Mar 2008 17:21:19 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2228688</guid><dc:creator>MeetNet</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2228688.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2228688</wfw:commentRss><description>&lt;p&gt;The latest MVC release does not have an override bool for OnError. What is the right way to catch things (pun intended) now?&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;ironside14:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;&lt;/p&gt;&lt;p&gt;...snip...&amp;nbsp;&lt;/p&gt;&lt;pre class="coloredcode"&gt;&lt;span class="kwd"&gt;public class&lt;/span&gt; MembershipAwareController : Controller
    {
        &lt;span class="kwd"&gt;protected override bool&lt;/span&gt; OnError(&lt;span class="kwd"&gt;string&lt;/span&gt; actionName, System.Reflection.MethodInfo methodInfo, Exception exception)
        {
            &lt;span class="kwd"&gt;if&lt;/span&gt; (exception &lt;span class="kwd"&gt;is&lt;/span&gt; System.Reflection.TargetInvocationException &amp;amp;&amp;amp;
                exception.InnerException &lt;span class="kwd"&gt;is&lt;/span&gt; System.Security.SecurityException )
       ...snip...&lt;/pre&gt;&amp;nbsp;&lt;font size="2"&gt;&lt;/font&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&amp;nbsp;</description></item><item><title>Re: Security in asp.net MVC application</title><link>http://forums.asp.net/thread/2187366.aspx</link><pubDate>Thu, 21 Feb 2008 15:14:31 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2187366</guid><dc:creator>JoshuaStroup</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2187366.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2187366</wfw:commentRss><description>&lt;p&gt;Good to know. Thank you Sliderhouserules I&amp;#39;m looking forward to that. Also I want to thank you Angus for the response to my email in which he stated and I&amp;#39;ll paraphrase:&lt;/p&gt;&lt;p&gt;-------------------------------------------- &lt;br /&gt;&lt;/p&gt;&lt;p&gt;You can simply create base functions in your controller that check user security permissions for example:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;isSiteAdmin()&lt;/li&gt;&lt;li&gt;isCustomer()&lt;/li&gt;&lt;li&gt;isShopUser()&lt;/li&gt;&lt;li&gt;isCustomerAdmin()&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Then create a logic trap at beginning of methods that need to be secured. (He used VB I&amp;#39;ll translate to C# as I&amp;#39;m more familiar with the syntax)&lt;/p&gt;&amp;nbsp;&lt;pre class="coloredcode"&gt;&lt;span class="kwd"&gt;if&lt;/span&gt; ( isAdmin() ) { 

   Throw New System.Security.SecurityException(&lt;span class="st"&gt;&amp;quot;Access Denied. User is unable to view this page.&amp;quot;&lt;/span&gt;);

} 

RenderView(&lt;span class="st"&gt;&amp;quot;Index&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&amp;nbsp;&lt;br /&gt;&lt;p&gt;--------------------------------------------&amp;nbsp;&lt;/p&gt;&lt;p&gt;Alternatively you could also (I took this from Maarten Balliauw) http://blog.maartenballiauw.be/post/2007/12/ASPNET-MVC-framework---Security.aspx&lt;/p&gt;&lt;p&gt;&lt;span class="kwrd"&gt;&amp;nbsp;&lt;pre class="coloredcode"&gt;&lt;span class="kwd"&gt;try&lt;/span&gt; {
    PrincipalPermission permission = &lt;span class="kwd"&gt;new&lt;/span&gt; PrincipalPermission(User.Identity.Name, &lt;span class="st"&gt;&amp;quot;Administrators&amp;quot;&lt;/span&gt;, &lt;span class="kwd"&gt;true&lt;/span&gt;);
    permission.Demand();
} &lt;span class="kwd"&gt;catch&lt;/span&gt; (SecurityException secEx) {
    &lt;span class="cmt"&gt;// Handle the Exception here...
    // Redirect to Login page, for example.&lt;/span&gt;
}&lt;/pre&gt;&amp;nbsp;&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;But I personally like Angus&amp;#39;s method better. Anyway this is just me trying to give back because of the great answers I receive from people willing to take time out and help our professions.&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Security in asp.net MVC application</title><link>http://forums.asp.net/thread/2185376.aspx</link><pubDate>Wed, 20 Feb 2008 19:17:30 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2185376</guid><dc:creator>sliderhouserules</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2185376.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2185376</wfw:commentRss><description>&lt;p&gt;In &lt;a href="http://weblogs.asp.net/scottgu/archive/2008/02/12/asp-net-mvc-framework-road-map-update.aspx"&gt;Scott Guthrie&amp;#39;s roadmap&lt;/a&gt; he showed the first look at what they&amp;#39;re calling Filters that he said will be in the next preview. It&amp;#39;s essentially PrinciplePermission, but you get to write your own filter and you can have it do whatever you want. You can apply it to the class and then everything inside that class (your controller) is subject to that, or you can apply it to individual methods/actions. That&amp;#39;s my take at least. Read his section &lt;b&gt;&lt;u&gt;5) New Filter Attribute Support for Controllers and Action Methods&lt;/u&gt;&lt;/b&gt; for more details.&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Security in asp.net MVC application</title><link>http://forums.asp.net/thread/2185356.aspx</link><pubDate>Wed, 20 Feb 2008 19:09:36 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2185356</guid><dc:creator>JoshuaStroup</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2185356.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2185356</wfw:commentRss><description>&lt;p&gt;Does anybody have a way of implementing some type of security inheritance. For example, it would be nice to call .Demand() on just my class and every Controller Action and View is authenticated and authorized if the user authenticates. I would like to use Code Access Security for overriding specific Actions or Views, but I also like the &amp;lt;location&amp;gt; tag functionality that applies system wide. Do I build a large global.asax that handles every exception and reroutes, then I just need to track what exceptions I use throughout the application? Or is there a better way? Maybe I&amp;#39;m missing something here for a solution or not understanding previous posts.&lt;/p&gt;&lt;p&gt;Respectfully,&lt;/p&gt;&lt;p&gt;Josh&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Security in asp.net MVC application</title><link>http://forums.asp.net/thread/2086761.aspx</link><pubDate>Wed, 02 Jan 2008 21:52:09 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2086761</guid><dc:creator>tgmdbm</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2086761.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2086761</wfw:commentRss><description>&lt;p&gt;i entered a competition to write the best pun, there were only 10 contestants and mine was clearly the best. I thought mine would win but... no pun in ten did.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Security in asp.net MVC application</title><link>http://forums.asp.net/thread/2086094.aspx</link><pubDate>Wed, 02 Jan 2008 15:57:29 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2086094</guid><dc:creator>ironside14</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2086094.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2086094</wfw:commentRss><description>&lt;p&gt;I&amp;#39;m taking the PrinicipalPermission route (no pun intended :) ).&lt;/p&gt;
&lt;p&gt;By creating a base controller class that&amp;#39;s security aware, I didn&amp;#39;t see the need for a special [ExceptionHandler] attribute for my simple case.&lt;/p&gt;
&lt;p&gt;As an example, a redirecting base controller that blindly redirects security exceptions to the login action of the &amp;quot;security&amp;quot; controller:&lt;/p&gt;&lt;pre class="coloredcode"&gt;&lt;span class="kwd"&gt;public class&lt;/span&gt; MembershipAwareController : Controller
    {
        &lt;span class="kwd"&gt;protected override bool&lt;/span&gt; OnError(&lt;span class="kwd"&gt;string&lt;/span&gt; actionName, System.Reflection.MethodInfo methodInfo, Exception exception)
        {
            &lt;span class="kwd"&gt;if&lt;/span&gt; (exception &lt;span class="kwd"&gt;is&lt;/span&gt; System.Reflection.TargetInvocationException &amp;amp;&amp;amp;
                exception.InnerException &lt;span class="kwd"&gt;is&lt;/span&gt; System.Security.SecurityException )
            {
                &lt;span class="cmt"&gt;// Use TempData as a container for a display message when redirecting the user to login.
                // I tried setting ViewData but it was always empty by the time the 
                // Login action is executed. TempData is meant for use on the next request only, so it seems a fitting spot for it.
                // There is some coupling here as this code assumes the Login controller will do something with TempData (like tell a view to render it).&lt;/span&gt;
                TempData[&lt;span class="st"&gt;&amp;quot;ErrorMessage&amp;quot;&lt;/span&gt;] = &lt;span class="st"&gt;&amp;quot;You must login to access this section of the site.&amp;quot;&lt;/span&gt;; 
                RedirectToAction(&lt;span class="st"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;, &lt;span class="st"&gt;&amp;quot;Security&amp;quot;&lt;/span&gt;);
            }
            &lt;span class="kwd"&gt;else base&lt;/span&gt;.OnError(actionName, methodInfo, exception);
            &lt;span class="kwd"&gt;return false&lt;/span&gt;;
        }
    }&lt;/pre&gt;&amp;nbsp;&lt;font size="2"&gt;&lt;/font&gt;</description></item><item><title>Re: Security in asp.net MVC application</title><link>http://forums.asp.net/thread/2085812.aspx</link><pubDate>Wed, 02 Jan 2008 13:49:15 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2085812</guid><dc:creator>cromwellryan</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2085812.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2085812</wfw:commentRss><description>&lt;p&gt;There is a post out &lt;a href="http://cromwellhaus.com/blogs/ryanc/archive/2007/12/19/asp-net-mvc-and-forms-authentication.aspx"&gt;here&lt;/a&gt; which describes setting up the ASP.Net Membership provider with the MVC framework.&amp;nbsp; It uses the &amp;lt;location/&amp;gt; config elements in the samples, but you can easily use declarative or explicit authorizations.&amp;nbsp; I&amp;#39;ll look at adding a short extension post about those two options.&amp;nbsp; I would agree that the &amp;lt;location/&amp;gt; config is poorly chosen as it&amp;#39;s dependent on the route configuration.&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Security in asp.net MVC application</title><link>http://forums.asp.net/thread/2051748.aspx</link><pubDate>Tue, 11 Dec 2007 00:34:54 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2051748</guid><dc:creator>Angus McDonald</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2051748.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2051748</wfw:commentRss><description>&lt;p&gt;We allow security permission settings to throw exceptions all the time, and then catch them in our base page and define how to handle a security permission error there (which for a non-logged in user is to re-direct them to the login page). This has the advantage of logging the access attempt as well as cleaning up your code.&lt;/p&gt;
&lt;p&gt;In MVC the idea of having a base controller that you extend makes perfect sense to me. That way you get to write your security handling code once, whilst each individual controller (or even &amp;lt;gasp!&amp;gt;&amp;nbsp;model) can decide what constitutes an unsecured attempt itself and just throw the right error at that point.&lt;/p&gt;</description></item><item><title>Re: Security in asp.net MVC application</title><link>http://forums.asp.net/thread/2051185.aspx</link><pubDate>Mon, 10 Dec 2007 18:45:50 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2051185</guid><dc:creator>pwelter34</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2051185.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2051185</wfw:commentRss><description>&lt;p&gt;In my experimenting, I couldn&amp;#39;t get the&amp;lt;location&amp;gt; element to work.&amp;nbsp; I like the idea of using PrincipalPermission.&amp;nbsp; However, that throws an exception.&amp;nbsp; The controller should redirect to login instead.&amp;nbsp; It should be easy enough to create a base controller to do this.&amp;nbsp; Would be really nice if this was built in to the framework though.&amp;nbsp; Also, throwing an exception doesn&amp;#39;t seem very efficient. &lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Security in asp.net MVC application</title><link>http://forums.asp.net/thread/2051168.aspx</link><pubDate>Mon, 10 Dec 2007 18:38:49 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2051168</guid><dc:creator>DavidHogue</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2051168.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2051168</wfw:commentRss><description>&lt;p&gt;I just tried the &amp;lt;location&amp;gt;, and it kind of works, but I wouldn&amp;#39;t use it.&amp;nbsp; I think the PrincipalPermission attribute (or just using some code like Mike343 suggested) will be the way to go with this.&lt;/p&gt;&lt;p&gt;I tried it with the default app that is generated that has a Home controller with Index and About actions.&amp;nbsp; When path=&amp;quot;Home&amp;quot; it does block /Home/anything, but you can still see / which is the same as /Home/Index.&amp;nbsp; Also setting path=Home/About did not stop me from going to /Home/About at all.&amp;nbsp; Plus the routes can be changed as Rob said.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Security in asp.net MVC application</title><link>http://forums.asp.net/thread/2051151.aspx</link><pubDate>Mon, 10 Dec 2007 18:28:00 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2051151</guid><dc:creator>robconery</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2051151.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2051151</wfw:commentRss><description>&lt;p&gt;You can indeed lock down your location using this method, but keep in mind we&amp;#39;re not using a &amp;quot;file request&amp;quot; scheme here anymore - this is all about RPC (in a sense). Additionally, users of your system might/can/will change the routes at some point, and if/when they do, they can break this FormsAuth security using &amp;lt;location&amp;gt;.&lt;/p&gt;
&lt;p&gt;Your best bet is to use PrinciplePermission on the contoller or method (with many thanks to Phil for this):&lt;/p&gt;[PrincipalPermission(SecurityAction.Demand,Role=&amp;quot;Administrator&amp;quot;)]&lt;br /&gt;[ControllerAction]&lt;br /&gt;public void Index(){&lt;br /&gt;...&lt;br /&gt;} 
&lt;p&gt;I have a blog post coming on this today. &lt;/p&gt;</description></item><item><title>Re: Security in asp.net MVC application</title><link>http://forums.asp.net/thread/2051116.aspx</link><pubDate>Mon, 10 Dec 2007 18:07:48 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2051116</guid><dc:creator>DavidHogue</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2051116.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2051116</wfw:commentRss><description>&lt;p&gt;I haven&amp;#39;t tried yet, but I sould assume the &amp;lt;location&amp;gt; and &amp;lt;authorization&amp;gt; tags in the web.config would do it.&lt;/p&gt;&lt;p&gt;
Something like this:&lt;br /&gt;

	&amp;lt;location path=&amp;quot;SomeController/SomeAction&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;system.web&amp;gt;&lt;br /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;authorization&amp;gt;&lt;br /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;allow users=&amp;quot;SomeUser&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;deny users=&amp;quot;*&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/authorization&amp;gt;&lt;br /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/system.web&amp;gt;&lt;br /&gt;
	&amp;lt;/location&amp;gt;&lt;/p&gt;&lt;p&gt;Once I get the CTP installed I&amp;#39;ll try it and see what happens.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>