<?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: Custom Authorization With Asp.net MVC</title>
	<atom:link href="http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/</link>
	<description>All Things .Net and Me</description>
	<lastBuildDate>Tue, 06 Jul 2010 04:32:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: bugeo</title>
		<link>http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/comment-page-1/#comment-238</link>
		<dc:creator>bugeo</dc:creator>
		<pubDate>Fri, 25 Jun 2010 15:48:06 +0000</pubDate>
		<guid isPermaLink="false">http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/#comment-238</guid>
		<description>Great!</description>
		<content:encoded><![CDATA[<p>Great!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Louboutin</title>
		<link>http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/comment-page-1/#comment-231</link>
		<dc:creator>Christian Louboutin</dc:creator>
		<pubDate>Thu, 10 Jun 2010 13:24:15 +0000</pubDate>
		<guid isPermaLink="false">http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/#comment-231</guid>
		<description>Thank you for sharing I wish I could go somwhere.</description>
		<content:encoded><![CDATA[<p>Thank you for sharing I wish I could go somwhere.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/comment-page-1/#comment-228</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sat, 22 May 2010 12:46:42 +0000</pubDate>
		<guid isPermaLink="false">http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/#comment-228</guid>
		<description>And how would I need to assign my custom role to a user I add in the controller?</description>
		<content:encoded><![CDATA[<p>And how would I need to assign my custom role to a user I add in the controller?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Muktadiur Rahman</title>
		<link>http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/comment-page-1/#comment-215</link>
		<dc:creator>Muktadiur Rahman</dc:creator>
		<pubDate>Sun, 18 Apr 2010 04:50:36 +0000</pubDate>
		<guid isPermaLink="false">http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/#comment-215</guid>
		<description>Nice post.thanks</description>
		<content:encoded><![CDATA[<p>Nice post.thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shalin</title>
		<link>http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/comment-page-1/#comment-197</link>
		<dc:creator>Shalin</dc:creator>
		<pubDate>Wed, 11 Nov 2009 19:01:47 +0000</pubDate>
		<guid isPermaLink="false">http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/#comment-197</guid>
		<description>Excellent post.

In addition I was looking for giving filtered access to records based on user&#039;s location. In other words, in my application, users are assigned different locations (branches). I want user from a branch should be able to access records entered by users of that branch only. I have UserLocation and Location table to manage assignment. Could you please guide me for this.

Thank you.</description>
		<content:encoded><![CDATA[<p>Excellent post.</p>
<p>In addition I was looking for giving filtered access to records based on user&#8217;s location. In other words, in my application, users are assigned different locations (branches). I want user from a branch should be able to access records entered by users of that branch only. I have UserLocation and Location table to manage assignment. Could you please guide me for this.</p>
<p>Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Schotime</title>
		<link>http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/comment-page-1/#comment-190</link>
		<dc:creator>Schotime</dc:creator>
		<pubDate>Wed, 16 Sep 2009 20:58:49 +0000</pubDate>
		<guid isPermaLink="false">http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/#comment-190</guid>
		<description>I would set this on login usually.

Thanks</description>
		<content:encoded><![CDATA[<p>I would set this on login usually.</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin</title>
		<link>http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/comment-page-1/#comment-188</link>
		<dc:creator>Kevin</dc:creator>
		<pubDate>Sun, 06 Sep 2009 17:24:07 +0000</pubDate>
		<guid isPermaLink="false">http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/#comment-188</guid>
		<description>Excellent tutorial. Now I&#039;m a bit confused:

Where/When would you set:
httpContext.Session[&quot;role&quot;]?

ThanX in advance.</description>
		<content:encoded><![CDATA[<p>Excellent tutorial. Now I&#8217;m a bit confused:</p>
<p>Where/When would you set:<br />
httpContext.Session["role"]?</p>
<p>ThanX in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ahrimaan</title>
		<link>http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/comment-page-1/#comment-179</link>
		<dc:creator>Ahrimaan</dc:creator>
		<pubDate>Wed, 05 Aug 2009 13:20:23 +0000</pubDate>
		<guid isPermaLink="false">http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/#comment-179</guid>
		<description>Hi,
Nice Post.
Now i Understand how the AuthorisazinFlags work.
Im sittin here and mull over a Problem:
I want to use the Authorization Flag but in another Form
Ive got a Detail View example /Report/1

Now a User got more than one Rights
Example : User a Rights 1 -&gt; 1024  , 2 -&gt; 2048
the 1 stands for the view and the 1024 for a Bitmask. I want to mage it as dynamicle as possible.

But i dont know how ... Any Ideas ?</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Nice Post.<br />
Now i Understand how the AuthorisazinFlags work.<br />
Im sittin here and mull over a Problem:<br />
I want to use the Authorization Flag but in another Form<br />
Ive got a Detail View example /Report/1</p>
<p>Now a User got more than one Rights<br />
Example : User a Rights 1 -&gt; 1024  , 2 -&gt; 2048<br />
the 1 stands for the view and the 1024 for a Bitmask. I want to mage it as dynamicle as possible.</p>
<p>But i dont know how &#8230; Any Ideas ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nizar</title>
		<link>http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/comment-page-1/#comment-162</link>
		<dc:creator>Nizar</dc:creator>
		<pubDate>Fri, 20 Feb 2009 22:55:04 +0000</pubDate>
		<guid isPermaLink="false">http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/#comment-162</guid>
		<description>Great post!  I&#039;ve been looking for how to implement custom authorization of MVC. Really like the idea of how you&#039;re managing the SiteRoles and/or logic.  Kinda confusing at first though.</description>
		<content:encoded><![CDATA[<p>Great post!  I&#8217;ve been looking for how to implement custom authorization of MVC. Really like the idea of how you&#8217;re managing the SiteRoles and/or logic.  Kinda confusing at first though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Schotime</title>
		<link>http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/comment-page-1/#comment-159</link>
		<dc:creator>Schotime</dc:creator>
		<pubDate>Thu, 19 Feb 2009 05:17:00 +0000</pubDate>
		<guid isPermaLink="false">http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/#comment-159</guid>
		<description>@Rasmus M
I have had a look at this and you can do it.

If you put the [CustomAuthroize] attribute on the controller and [CustomAuthroize(Roles = SiteRoles.Admin)] on the action method then only admin people will be allowed through. If you try to access the page with a SiteRoles.User then you will be sent to the &quot;NotAuth&quot; view. This can easily be changed.

&lt;strong&gt;    public class CustomAuthorizeAttribute : AuthorizeAttribute
    {
        // the &quot;new&quot; must be used here because we are overriding the Roles property on the underlying class
        public new SiteRoles Roles;

        private bool FailedRolesAuth = false;

        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (httpContext == null)
                throw new ArgumentNullException(&quot;httpContext&quot;);

            if (!httpContext.User.Identity.IsAuthenticated)
                return false;

            string[] users = Users.Split(&#039;,&#039;);

            if (!httpContext.User.Identity.IsAuthenticated)
                return false;

            if (users.Length &gt; 0 &amp;&amp; !users.Contains(StateManager.ContactName, StringComparer.OrdinalIgnoreCase))
                return false;

SiteRoles role = (SiteRoles)httpContext.Session[&quot;role&quot;];

            if (Roles != 0 &amp;&amp; (Roles &amp; role) != role)
            {
                FailedRolesAuth = true;
                return false;
            }

            return true;
        }

        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);
            if (FailedRolesAuth)
            {
                filterContext.Result = new ViewResult { ViewName = &quot;NotAuth&quot; };
            }
        }
    }&lt;/strong&gt;


This will redirect you to the &quot;NotAuth&quot; view if you fail the role logic.</description>
		<content:encoded><![CDATA[<p>@Rasmus M<br />
I have had a look at this and you can do it.</p>
<p>If you put the [CustomAuthroize] attribute on the controller and [CustomAuthroize(Roles = SiteRoles.Admin)] on the action method then only admin people will be allowed through. If you try to access the page with a SiteRoles.User then you will be sent to the &#8220;NotAuth&#8221; view. This can easily be changed.</p>
<p><strong>    public class CustomAuthorizeAttribute : AuthorizeAttribute<br />
    {<br />
        // the &#8220;new&#8221; must be used here because we are overriding the Roles property on the underlying class<br />
        public new SiteRoles Roles;</p>
<p>        private bool FailedRolesAuth = false;</p>
<p>        protected override bool AuthorizeCore(HttpContextBase httpContext)<br />
        {<br />
            if (httpContext == null)<br />
                throw new ArgumentNullException(&#8220;httpContext&#8221;);</p>
<p>            if (!httpContext.User.Identity.IsAuthenticated)<br />
                return false;</p>
<p>            string[] users = Users.Split(&#8216;,&#8217;);</p>
<p>            if (!httpContext.User.Identity.IsAuthenticated)<br />
                return false;</p>
<p>            if (users.Length > 0 &#038;&#038; !users.Contains(StateManager.ContactName, StringComparer.OrdinalIgnoreCase))<br />
                return false;</p>
<p>SiteRoles role = (SiteRoles)httpContext.Session["role"];</p>
<p>            if (Roles != 0 &#038;&#038; (Roles &#038; role) != role)<br />
            {<br />
                FailedRolesAuth = true;<br />
                return false;<br />
            }</p>
<p>            return true;<br />
        }</p>
<p>        public override void OnAuthorization(AuthorizationContext filterContext)<br />
        {<br />
            base.OnAuthorization(filterContext);<br />
            if (FailedRolesAuth)<br />
            {<br />
                filterContext.Result = new ViewResult { ViewName = &#8220;NotAuth&#8221; };<br />
            }<br />
        }<br />
    }</strong></p>
<p>This will redirect you to the &#8220;NotAuth&#8221; view if you fail the role logic.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
