4
[RequireHttps]
public class AccountController : BaseWebAppController

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

George Duckett
  • 31,770
  • 9
  • 95
  • 162
Evinrude
  • 41
  • 2

3 Answers3

1

You could use method described here: ASP.NET MVC RequireHttps in Production Only

Community
  • 1
  • 1
msergey
  • 592
  • 1
  • 4
  • 12
  • The methods are not working while overriding RequireHttpsAttribute – Evinrude Jun 09 '11 at 10:08
  • Sorry, I didn't give exactly link to answer. I mean conditional compilaton, not overriding attribute. This one is correct: http://stackoverflow.com/questions/1639707/asp-net-mvc-requirehttps-in-production-only/1639831#1639831. – msergey Jun 09 '11 at 11:28
0

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
Serj Sagan
  • 28,927
  • 17
  • 154
  • 183
0

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.

Chao
  • 3,033
  • 3
  • 30
  • 36