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

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -