What's up!

Pyaarey Allah!
Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

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

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.

Saturday, January 29, 2011

Development Updates Power post

0 comments

I will include ASP.NET MVC3 stuff and then I will also add some misc stuff which I think you should be aware of along-with the news of MVC3.

MVC3 Code Samples From MSDN
 MVC 3 with Razor
 MVC 3 Filters
 MVC 3 Remote Client Validation
Getting Started with MVC C# 3
Getting Started with MVC 3 VB

Some important stuff from Scott Gu's Blog
ASP.NET MVC 3: Layouts and Sections with Razor 


IIS/ASP.NET Application Hosting and Management
------------------------------------------------------------
Auto-Start ASp.NET Applications
http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx

Common performance issues on ASP.NET web sites
http://blogs.msdn.com/b/mcsuksoldev/archive/2011/01/19/common-performance-issues-on-asp-net-web-sites.aspx

Microsoft Web Farm Framework
-------------------------------------
Introducing the Microsoft Web Farm Framework
http://weblogs.asp.net/scottgu/archive/2010/09/08/introducing-the-microsoft-web-farm-framework.aspx

Microsoft Web Farm Framework 2.0
http://weblogs.asp.net/scottgu/archive/2011/01/20/microsoft-web-farm-framework-2-0.aspx

IIS.net Official Complete Guide to Web Farm Framework 2.0
http://learn.iis.net/page.aspx/905/microsoft-web-farm-framework-20-for-iis-7/



C#
----
Optional Parameters and Named Arguments in C# 4 (and a cool scenario w/ ASP.NET MVC 2)
http://weblogs.asp.net/scottgu/archive/2010/04/02/optional-parameters-and-named-arguments-in-c-4-and-a-cool-scenario-w-asp-net-mvc-2.aspx

Nuget
-------
Adding packages to nuget.org
http://codingreflection.com/2011/01/26/adding-packages-to-nuget-org/


CSS3
------
CSS Agent(automatic vendor prefixes,constants,Minification)
http://www.keithclark.co.uk/labs/cssagent/

VSTS2010
-----------
Box Selection and Multi-Line Editing with VS 2010
http://weblogs.asp.net/scottgu/archive/2010/04/26/box-selection-and-multi-line-editing-with-vs-2010.aspx

VS 2010 Productivity Power Tools Update (with some cool new features)
http://weblogs.asp.net/scottgu/archive/2010/07/19/vs-2010-productivity-power-tools-update-with-some-cool-new-features.aspx

Fun Visual Studio 2010 Wallpapers
http://weblogs.asp.net/scottgu/archive/2010/05/12/fun-visual-studio-2010-wallpapers.aspx

Download and Share Visual Studio Color Schemes
http://weblogs.asp.net/scottgu/archive/2010/04/29/download-and-share-visual-studio-color-schemes.aspx

Visual Studio 2010 Keyboard Shortcuts
http://weblogs.asp.net/scottgu/archive/2010/07/29/visual-studio-2010-keyboard-shortcuts.aspx

Javascript Code Snippets in Visual Studio
http://weblogs.asp.net/scottgu/archive/2009/09/04/asp-net-html-javascript-snippet-support-vs-2010-and-net-4-0-series.aspx

Searching and Navigating Code in VS 2010 (VS 2010 and .NET 4.0 Series)
http://weblogs.asp.net/scottgu/archive/2009/10/21/searching-and-navigating-code-in-vs-2010-vs-2010-and-net-4-0-series.aspx

Add Reference Dialog Improvements (VS 2010 and .NET 4.0 Series)
http://weblogs.asp.net/scottgu/archive/2009/10/29/add-reference-dialog-improvements-vs-2010-and-net-4-0-series.aspx

VS 2010 SP1 (Beta) and IIS Express
http://weblogs.asp.net/scottgu/archive/2011/01/03/vs-2010-sp1-beta-and-iis-developer-express.aspx

HTML5 & CSS3 in Visual Studio 2010 SP1
http://blogs.msdn.com/b/webdevtools/archive/2011/01/27/html5-amp-css3-in-visual-studio-2010-sp1.aspx

Database Deployment with the VS 2010 Package/Publish Database Tool
http://rachelappel.com/deployment/database-deployment-with-the-vs-2010-package-publish-database-tool/

ASP.NET MVC2
-----------------
ASP.NET MVC 2: Strongly Typed Html Helpers
http://weblogs.asp.net/scottgu/archive/2010/01/10/asp-net-mvc-2-strongly-typed-html-helpers.aspx

ASP.NET MVC 2: Model Validation
http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx

ASP.NET MVC3
-----------------
MSDN Official Guide ASP.NET MVC3
http://msdn.microsoft.com/en-us/library/gg416514%28v=vs.98%29.aspx

Introducing ASP.NET MVC 3 (Preview 1)
http://weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx

Announcing NuPack, ASP.NET MVC 3 Beta, and WebMatrix Beta 2
http://weblogs.asp.net/scottgu/archive/2010/10/06/announcing-nupack-asp-net-mvc-3-beta-and-webmatrix-beta-2.aspx

Announcing the ASP.NET MVC 3 Release Candidate
http://weblogs.asp.net/scottgu/archive/2010/11/09/announcing-the-asp-net-mvc-3-release-candidate.aspx

Announcing ASP.NET MVC 3 (Release Candidate 2)
http://weblogs.asp.net/scottgu/archive/2010/12/10/announcing-asp-net-mvc-3-release-candidate-2.aspx

ASP.NET MVC 3: New @model keyword in Razor
http://weblogs.asp.net/scottgu/archive/2010/10/19/asp-net-mvc-3-new-model-directive-support-in-razor.aspx

ASP.NET MVC 3: Server-Side Comments with Razor
http://weblogs.asp.net/scottgu/archive/2010/11/12/asp-net-mvc-3-server-side-comments-with-razor.aspx
http://weblogs.asp.net/scottgu/archive/2011/01/13/announcing-release-of-asp-net-mvc-3-iis-express-sql-ce-4-web-farm-framework-orchard-webmatrix.aspx

Running an ASP.NET MVC 3 app on a web server that doesn’t have ASP.NET MVC 3 installed
http://weblogs.asp.net/scottgu/archive/2011/01/18/running-an-asp-net-mvc-3-app-on-a-web-server-that-doesn-t-have-asp-net-mvc-3-installed.aspx

Partial Page Output Caching in ASP.NET MVC 3 - OutputCache Attribute
http://davidhayden.com/blog/dave/archive/2011/01/25/PartialPageOutputCachingASPNETMVC3.aspx

Dependency Injection with ASP MVC 3–Distilled and Simplified
http://www.lostechies.com/blogs/johnvpetersen/archive/2011/01/23/dependency-injection-with-asp-mvc-3-distilled-and-simplified.aspx

Dependency Injection in MVC 3–with Views
http://www.lostechies.com/blogs/johnvpetersen/archive/2011/01/24/dependency-injection-in-mvc-3-with-views.aspx

ASP.NET Razor Converter(ASPX TO Razor templates)
https://github.com/telerik/razor-converter

How To: Add Mobile Pages to Your ASP.NET Web Forms / MVC Application
http://www.asp.net/learn/whitepapers/add-mobile-pages-to-your-aspnet-web-forms-mvc-application

ViewBag in ASP.NET MVC 3
http://davidhayden.com/blog/dave/archive/2011/01/19/ViewBagAspNetMvc3.aspx

ASP.NET MVC 3–What’s in it for you?
http://weblogs.asp.net/jgalloway/archive/2011/01/18/asp-net-mvc-3-what-s-in-it-for-you.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+jongalloway+%28Jon+Galloway%29&utm_content=Twitter

Configurable Global Action Filters for ASP.NET MVC
http://odetocode.com/Blogs/scott/archive/2011/01/15/configurable-global-action-filters-for-asp-net-mvc.aspx

A Comparison of Three jQuery Modal Dialogs for ASP.NET MVC
http://www.codeproject.com/KB/ajax/jQuery-Modal-Dialogs.aspx

Jquery
--------
Microsoft's  stephen walther's Proposal of Jquery templates on the jquery forum
http://forum.jquery.com/topic/jquery-templates-proposal

jQuery Templates and Data Linking (and Microsoft contributing to jQuery)
http://weblogs.asp.net/scottgu/archive/2010/05/07/jquery-templates-and-data-linking-and-microsoft-contributing-to-jquery.aspx

T4 Templates
----------------
T4 Templates and the Entity Framework
http://msdn.microsoft.com/en-us/gg558520

Monday, December 27, 2010

Getting Current Index In Foreach Loop

1 comments


foreach (var obj in this.Sizes.Select((sz, i) => new {Size =sz, Index = i }))
{
ViewSize sizeObject = obj.Size;
int currentIndex = obj.Index;
Response.Write("index=" + currentIndex + ": class=" + sizeObject.ClassName);
}

Thursday, December 9, 2010

Rock Library gone open source

1 comments

Rock Library is my own and my favorite library. People were after it for a long time. Finally gone open source.
Hosted on the google code hosting Click here to get the source

Friday, November 26, 2010

C# Training Milestones

0 comments

when u need to learn C#
--------------------------
ok about basics. there are unlimited facts about a language .. just make sure that you practically know Inheritance, Abstract Class, Interface, Virtual members, Abstract Members,
Loop conditions(for loop, while loop, foreach loop, do while loop),
If Else statement, Switch Case Statement,
What are TYPEs, Enumeration,
variable declaration,
Delegates, Events,
Generics,
Linq, primitive types(i.e char, bool, string, int, long, float, double, decimal etc etc),
operators(i.e +, -, =, ++, -- etc etc ) ,
comparison operators(=, <, >, <>, !, !=, <=, >= etc etc) , custom types(like your own classes, enums, delegates),
basic string manipulation(i.e take substring, count characters, iterate character by character, joining etc ), using collections(Array, List, HashTable, array list), iterating over a collection, finding data.