Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to enable Security host transport security in asp.net with c#. I am using visual studio 2008 with c#. I am using IIS 7 and added a SSL Certificate and installed the Url rewrite module(downloaded rewrite_amd64_en-US.msi) and re started IIS.

I am not able to redirect HTTP to HTTPS even after adding the below rule in the web.config file. On changing from HTTPS to HTTP I am getting Resource not found issue.

What I have tried:

In web.config added

<system.webServer>
       <rewrite>
           <rules>
               <rule name="HTTP to HTTPS redirect" stopProcessing="true">
                   <match url="(.*)" />
                   <conditions>
                       <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                   </conditions>
                   <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
                       redirectType="Permanent" />
               </rule>
           </rules>
           <outboundRules>
               <rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
                   <match serverVariable="RESPONSE_Strict_Transport_Security"
                       pattern=".*" />
                   <conditions>
                       <add input="{HTTPS}" pattern="on" ignoreCase="true" />
                   </conditions>
                   <action type="Rewrite" value="max-age=31536000" />
               </rule>
           </outboundRules>
       </rewrite>
Posted
Updated 10-Dec-18 22:13pm
v3
Comments
Bryian Tan 11-Dec-18 15:32pm    
1. Did you check if the URL Rewrite Module is installed?
URL Rewrite : The Official Microsoft IIS Site[^]
2. try this way see if it make any different:
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />

3. make sure the server not using different port other than 80/ 443

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900