JP Hellemons Building E-commerce web applications

Asp.Net switch site to SSL (https) the easy way

1. July 2011 15:24by JP Hellemons in IIS

For this small article, I assume that you have an Asp.Net web application running on IIS and that you have setup your SSL certificate. So navigating to https://www.yoursite.com works. This blog post will explain how to redirect all http traffic to https in several easy steps.

1. Get the Web Platform Installer (it’s free!) from Microsoft  http://www.microsoft.com/downloads/en/details.aspx?FamilyID=32b0dfe5-f139-4e1c-b412-3da39f50bbf9 

2. After you have opened the WebPI (Web Platform Installer) search for: Rewrite

image

3. Install the component!

4. Open your web.config (I used notepad++ )

5. Merge this into your web.config:

<configuration>    
<system.webServer>
<rewrite>
<rules> 
<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="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

 

And your done, when you hit save. The IIS will restart if the web.config is modified, so the new rule is now enabled!

kick it on DotNetKicks.com Shout it

Share or Bookmark this post…
  • del.icio.us
  • Digg
  • DotNetKicks
  • eKudos
  • E-Mail
  • Facebook
  • Google
  • LinkedIn
  • msdn Social
  • Reddit
  • NuJIJ
  • Slashdot
  • TwitThis
  • StumbleUpon

Comments (3) -

Ryan 3/6/2012 12:34:14 PM United States #
Ryan

Hi,
Great article, however I'm having issues making it redirect for mysite.com (without www.) Any idea how I can change this to work for both www and non-www. Thanks!

Reply

JP Hellemons 3/6/2012 12:38:38 PM Netherlands #
JP Hellemons

Hi Ryan, try:

<rule name="CanonicalHostNameRule1">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^www\.jphellemons\.nl$" negate="true" />
                    </conditions>
                    <action type="Redirect" url="http://www.jphellemons.nl/{R:1}" />
                </rule>

Reply

Samir 5/7/2012 9:59:15 AM Azerbaijan #
Samir

This rule doesn't include directories http://localhost/myapp/Test.aspx redirects to https:///localhost/Test.aspx
Please help, how to make it include directories?

Reply

Pingbacks and trackbacks (3)+

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading