c# - Redirect HTTP to HTTPS for all pages -
if type in example.com redirects https://example.com want to. when typing http://example.com/blog still redirects https://example.com
<rewrite> <rules> <clear/> <rule name="force https" stopprocessing="true"> <match url="(.*)" /> <conditions> <add input="{https}" pattern="off" ignorecase="true"/> </conditions> <action type="redirect" url="https://{http_host}/{r:1}" appendquerystring="false" redirecttype="permanent" /> </rule> </rules> </rewrite>
how can make add https whatever user wrote?
you can use attribute [system.web.mvc.requirehttps] controller.
if need on controller, can use following code (only asp.net mvc6/core).
public void configureservices(iservicecollection services) { services.addmvc(options => { options.filters.add(typeof(requirehttpsinproductionattribute)); }); }
note: , can use hsts avoid client use http request next time.
<system.webserver> <httpprotocol> <customheaders> <add name="strict-transport-security" value="max-age=31536000"/> </customheaders> </httpprotocol> </system.webserver>
Comments
Post a Comment