How can I conditionally enable or disable [RequireHttps]

[RequireHttps] public class AccountController : BaseWebAppController 

I need to conditionally enable or disable requirehttps for this controller. What should I do?

+4
source share
3 answers

You can use the method described here: ASP.NET MVC RequireHttps only in production

+1
source

This is a bit complicated, not knowing what your conditions are, but I would go the way of getting an attribute from RequireHttpsAttribute and overriding HandleNonHttpsRequest. In this method, you can check your condition and react accordingly.

0
source

Like this:

 public class ProdOnlyRequireHttpsAttribute : RequireHttpsAttribute { public override void OnAuthorization(AuthorizationContext filterContext) { if (!Statics.IsPROD()) return; base.OnAuthorization(filterContext); } } 

Then

 [ProdOnlyRequireHttps] public class HomeController : Controller 
0
source

All Articles