Skip to content

Instantly share code, notes, and snippets.

@dannylloyd
Last active January 8, 2016 16:16
Show Gist options
  • Select an option

  • Save dannylloyd/986d4a1c0fe56aeefb27 to your computer and use it in GitHub Desktop.

Select an option

Save dannylloyd/986d4a1c0fe56aeefb27 to your computer and use it in GitHub Desktop.
Custom attribute in MVC
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Web.Core.Common
{
public class AuthorizeForEnvironmentsAttribute : AuthorizeAttribute
{
protected readonly Web.Core.Common.Environments[] environments;
public AuthorizeForEnvironmentsAttribute(params Web.Core.Common.Environments[] environments)
{
this.environments = environments;
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (environments.Contains(Web.Core.Common.Settings.Environment))
{
return base.AuthorizeCore(httpContext);
}
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment