开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜