Last post Jul 11, 2017 01:10 PM by priyalwalpita
Jul 11, 2017 12:53 PM|TheCoder007|LINK
I am developing a Web application using ASP.Net Core. I need to make the HTTPS mandatory programatically irrespective of the hosting environment.
What is the easiest way that I can achieve this ? It would be great if you can provide me a code segment as well.
Jul 11, 2017 01:10 PM|priyalwalpita|LINK
I hope you are using the ASP.Net Core MVC ? If so, the easiest thing you can do is [RequireHttps] attribute in your controller. This will filter all requests to the respective controller and filter out all non HTTPS requests.
If you need to enforce this filter to the whole application, you need to enforce this filtering in the startup class as follows.
private IHostingEnvironment _env;
public startup(IHostingEnvironment env)
public void ConfigureServices(Iservicecollection services)
services.Configure<MvcOptions>(o=> o.Filters.Add(new RequireHttpsAttribute()));