Using the [RequireHttps]
port in an ASP.NET MVC application causes a redirect to HTTPS on port 443 if the user attempts to access the application over HTTP.
However, in IIS Express, the application will probably not running on port 443. It will, instead, be running on something like port 44301.
I've found various tips for replacing RequireHttpsAttribute
with an implementation that takes the alternative port number as a parameter, or reads it from Web.config
.
This is clunky, because it requires configuration in more than one place.
Is there any way to do this -- programmatically -- in a generic fashion?
Without trying to pre-empt the answers, some options occur to me:
- Is there any way to discover the bindings being used by the instance of IIS or IIS Express that's hosting my app?
- Is there any way to read
applicationHost.config
for the current IIS / IIS Express host?