What's up!

Pyaarey Allah!
Showing posts with label MVC. Show all posts
Showing posts with label MVC. Show all posts

Monday, March 26, 2012

Empty MVC3 application is not so empty

0 comments

How can you say this is NEW EMPTY MVC application when there are 6 Nuget packages are palced already, 20 javascript files are placed, 13 images and 15 CSS files are there. ........

Tuesday, March 6, 2012

My favorite shortcut key combinations

0 comments


All mapped with ALT key :P


1 - Compile Current Project


2 - Start outlining
3 - Toggle outline on current block
4 - Toggle all blocks


5 - Comment selection
6 - Uncomment selection


7 - Find in files
8 - Repalce in files


9 - Insert Snippet


0 - Attach to process
= - Attach to Current IIS process(VS Commands customized shortcut)


Q - Format selection
W - Full document format


Z - Zen expand (with zen coding VS plugin)
X - Zen Wrap (with zen coding VS plugin)


Space - save all items

A - Close currently selected window
S - Close all but currently selected window

Friday, July 15, 2011

Thursday, May 26, 2011

Fix firefox localhost slow connections/browsing/rendering

0 comments

  1. Open ff and write this command in address base " about:config "
  2. Tell firefox that you will be helpful while editing configuration
  3. in the FilterBox type " v6 "
  4. double click on the entry network.dns.disableIPv6 so it should be be " TRUE " now.
  5. You are done, rock on!

Friday, February 25, 2011

Implementing a custom ASP.NET MVC authorization filter

0 comments

I created a custom class inheriting from FilterAttribute and implementing

IAuthorizationFilter:
     public class CustAuthorizeAttribute : FilterAttribute, IAuthorizationFilter
     {
         public CustAuthorizeAttribute(params UserRole[] acceptedRoles)
         {
             _acceptedRoles = acceptedRoles;   
         }
      
         public void OnAuthorization(AuthorizationContext filterContext)
         {
            User currentUser = UserHelper.GetCurrentUser();
     
            if (!currentUser.IsInRole(_acceptedRoles))
                throw new CustUnauthorizedAccessException();
      }
     
        private readonly UserRole[] _acceptedRoles;
     
        private IUserHelper _userHelper;
        public IUserHelper UserHelper
        {
            get
            {
                if (_userHelper == null)
                    _userHelper = ObjectFactory.Create();
     
                return _userHelper;
            }
            set { _userHelper = value; }
        }
    }
My constructor takes a params list of one or more UserRole enumeration values. IAuthorizationFilter only has one method that must be implemented: OnAuthorization. In my implementation, I'm checking whether the current user is in one of the roles supplied to the constructor. (My User.IsInRole method also takes a params list of accepted roles.) (I wish I could set my IUserHelper implementation via constructor injection instead of having to resolve it from my IOC container within the attribute class, but I don't think that's possible, since .NET attribute constructor syntax doesn't it.) Adding authorization for a controller action is as easy as applying the attribute to an action (or it could be applied at the class level to be in effect for all of the controller's actions:
 public class AdministrationController : Controller
     {
         [CustAuthorize(UserRole.Administrator)]
         public virtual ActionResult AdministerUsers()
         {
             return View();
         }
      
         [CustAuthorize(UserRole.Administrator, /*or*/ UserRole.AdminAssistant)]
        public virtual ActionResult Reports()
        {
            return View();
        }
    }

In the example above, only users with an "Administrator" role are authorized for the "AdministerUsers" view, and users with either an "Administrator" or "AdminAssistant" role can see the "Reports" view. If users without the required roles try to go to those views, an exception will be thrown.