Determine if ASP.NET application is running locally
This worked for me with Application_Start
if (!HostingEnvironment.IsDevelopmentEnvironment)
{
GlobalFilters.Filters.Add(new RequireHttpsAttribute());
}
To know more about how IsDevelopmentEnvironment is set, please look at the following thread.
In ASP.NET, what determines the value of HostingEnvironment.IsDevelopmentEnvironment?
See HttpRequest.IsLocal
bool isLocal = HttpContext.Current.Request.IsLocal;
You can check the Request.IsLocal property