Thursday, August 30, 2012

ASP.NET MVC 4 Useful Links


Release Note
       http://www.asp.net/whitepapers/mvc4-release-notes

Using Asynchronous Methods in ASP.NET MVC 4

         http://www.asp.net/mvc/tutorials/mvc-4/using-asynchronous-methods-in-aspnet-mvc-4

Bundling and Minification


Asp.net MVC 4 Article Series by Nandip Makwana

           

Create a Custom Authorize Attribute in ASP.NET MVC


 Sample code for a creating a simple Authorize attribute. 
A user with "admin" username can only access the action which is decorated by [AdminAuthorize] attribute.

  
public class AdminAuthorize : AuthorizeAttribute
    {
        //return true if username is admin else return false
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (!httpContext.User.Identity.IsAuthenticated)
            {
                return false;
            }
            Users = httpContext.User.Identity.Name.ToLower();
 
            return (Users == "admin");
        } 
    }