I had the same situation as described by Doug
My solution: 1) Factory user controller created. This is necessary to get the ControllerContext in my https user attribute.
public class CustomControllerFactory : DefaultControllerFactory { public override IController CreateController(RequestContext requestContext, string controllerName) { var controller = base.CreateController(requestContext, controllerName); HttpContext.Current.Items["controllerInstance"] = controller; return controller; } } }
2) The following is written in the Application_Start function from the Global.asax file:
ControllerBuilder.Current.SetControllerFactory(new CustomControllerFactory());
3) Defined user attribute https:
public class CustomRequireHttpsAttribute : System.Web.Mvc.RequireHttpsAttribute { public bool RequireSecure = false; public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext) { if (RequireSecure && !((Controller)HttpContext.Current.Items["controllerInstance"]).ControllerContext.IsChildAction) { base.OnAuthorization(filterContext); } } }
4) Using the new attribute to define the account controller: [CustomRequireHttps]
Taras pelenio
source share