ASP.NET – Setup HTTPS on web.config

//ASP.NET – Setup HTTPS on web.config

ASP.NET – Setup HTTPS on web.config

HTTP code:

<rewrite>
      <rules>		
        <rule name="www redirect" enabled="true" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" />
            <add input="{HTTPS}" pattern="off" />
          </conditions>
          <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" />
        </rule>
        <rule name="www redirect https" enabled="true" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" />
            <add input="{HTTPS}" pattern="on" />
          </conditions>
          <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" />
        </rule>
        <rule name="RequestBlockingRule1" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_USER_AGENT}" pattern="^Libwww-perl$" />
          </conditions>
          <action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission to view this directory or page using the credentials that you supplied." />
      </rule>
   </rules>
</rewrite>

HTTPS code:

    <rewrite>
      <rules>
	  <rule name="Redirect to https" stopProcessing="true">
			<match url=".*" />
			<conditions>
				<add input="{HTTPS}" pattern="off" ignoreCase="true" />
			</conditions>
			<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
		</rule>		
      </rules>
    </rewrite>
By |2020-08-11T12:08:26-06:00August 11th, 2020|Web Developer|Comments Off on ASP.NET – Setup HTTPS on web.config

About the Author: