﻿using System;
using System.Web.Mvc;

namespace Website.Security
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
	public class EnforceHttpsAttribute : RequireHttpsAttribute
	{
		public override void OnAuthorization(AuthorizationContext filterContext)
		{
			if(filterContext == null)
			{
				throw new ArgumentNullException(nameof(filterContext));
			}

			if(filterContext.HttpContext.Request.IsSecureConnection)
			{
				return;
			}

			if(string.Equals(filterContext.HttpContext.Request.Headers["X-Forwarded-Proto"],
				"https",
				StringComparison.InvariantCultureIgnoreCase))
			{
				return;
			}

			if(filterContext.HttpContext.Request.IsLocal)
			{
				return;
			}

			HandleNonHttpsRequest(filterContext);
		}
	}
}
﻿using System;
using System.Web.Mvc;

namespace Website.Security
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
	public class EnforceHttpsAttribute : RequireHttpsAttribute
	{
		public override void OnAuthorization(AuthorizationContext filterContext)
		{
			if(filterContext == null)
			{
				throw new ArgumentNullException("filterContext");
			}

			if(filterContext.HttpContext.Request.IsSecureConnection)
			{
				return;
			}

			if(string.Equals(filterContext.HttpContext.Request.Headers["X-Forwarded-Proto"],
				"https",
				StringComparison.InvariantCultureIgnoreCase))
			{
				return;
			}

			if(filterContext.HttpContext.Request.IsLocal)
			{
				return;
			}

			HandleNonHttpsRequest(filterContext);
		}
	}
}
Remove nameof operator because it caused a build error in AppHarbor
Remove nameof operator because it caused a build error in AppHarbor

Will have to investigate if AH supports c# 6 yet
