Monthly Archives: August 2013

Why JavaScript Will Become The Dominant Programming Language Of The Enterprise

That’s the title of an article over at Read-Write-Web. Good to know the advice I started giving two years ago to people interested in learning or getting into programming (learn javascript!) was on the nail. This trend isn’t going to be slowing down either.

Read the article here: http://readwrite.com/2013/08/09/why-javascript-will-become-the-dominant-programming-language-of-the-enterprise

And now for some obvious understatement…

Something changed. Because it’s been so long since I’ve copied and pasted code to this blog I don’t recall if it’s the settings in Visual Studio that changed or if it’s the WordPress blog post editor.  At one point in the past it was clearly possible to copy code maintaining the fonts, colors, formatting, etc but in that last post about custom attributes in MVC all of that was lost.  It’s possible that the older post with correct formatting was done from an install of Visual Studio that had an extension meant to make easy for this activity… I recall having something like that installed at one time.

I’ll try to figure it out and make whatever changes are needed so that future posts about code will look the same on WP as they do in my code editor.  Riveting stuff, I know… but it’s somewhat important to me.

Custom Role Attributes in ASP.NET MVC

Here is the code for defining and applying custom Role attributes in ASP.NET MVC. This specific example checks to see if the user is part of a given Active Directory group, but changing this to a custom validation should be fairly obvious.

Code in the controller:

[MyAuthorizeAttribute(Roles = “{AD group goes here}”)]
//ActionMethod code goes here…

Code to implement the attribute:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MyProject.Controllers
{
public class MyAuthorizeAttribute : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (httpContext.User.Identity.IsAuthenticated)
{
UserGroups groups = new MyProject.Shared.ActiveDirectory.UserGroups(HttpContext.Current.User.Identity.Name);
var roles = ( Roles ?? string.Empty).Split(‘|’);

//if granted role exist in users group or if its admin-overload ( admin permission) for all menu
if (groups.IsInDistGroup(Roles) )
{
return true;
}
}
return base.AuthorizeCore(httpContext);
}

protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
filterContext.Result = new ViewResult
{
ViewName = “~/Views/Shared/NotValid.cshtml”
};
}
}
}