How do i conditionally Enable or disable [RequireHttps]
[RequireHttps]
public class AccountContro开发者_运维百科ller : BaseWebAppController
I need to conditionally enable or disable requirehttps to this controller. What do I have to do?
You could use method described here: ASP.NET MVC RequireHttps in Production Only
It's a bit tricky without knowing what your conditions are but I would go along the route of deriving an attribute from RequireHttpsAttribute and overriding HandleNonHttpsRequest. In that method you should be able to test your condition and react accordingly.
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
精彩评论