Wednesday, April 11, 2012

Enabling SSL on specific pages. IIS Express and VS 2010

I have just installed sp1 for visual studio 2010 and now i am debugging my asp.net projects and websites with IIS Express. I know i can enable ssl from project's properties. but what i want to figure out is how to enable and require SSL for few pages like Login.aspx and Register.aspx. I believe, in IIS we can do such things from IIS manager but, there seems to be no management area for IIS express except a small icon in system tray. I have not installed IIS express with webmatrix but as a standalone application.

regards



Answer:


You can do it with Url Rewriting. If you have a certificate installed for your site in IIS, but you have headers configured for https and http, then the pages of the site can be accessed via either method. You can use a url rewrite to force all requests to a given page to be https, like so:
<rewrite >
  <rules>
    <clear />
    <rule name="Redirect Login Page" stopProcessing="true">
      <match url="^Login.aspx(.*)" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/Login.aspx{R:1}" />
    </rule>
I have used this in a few applications and it works well.

No comments:

Post a Comment