How do I enable ssl for all controllers in mvc application
The [RequireHttps]
attribute is inherited, so you could create a base controller, apply the attribute to that, and then derive all your controllers from that base.
[RequireHttps]
public abstract class BaseController : Controller
{}
public class HomeController : BaseController
{}
public class FooController : BaseController
{}
Use the RegisterGlobalFilters
method in your FiltersConfig
.
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new RequireHttpsAttribute());
}
}