Reputation: 100
I have an Azure Cloud Service set up as follows:
<Sites>
<Site name="Web" physicalDirectory="../SampleWebsite/">
<Bindings>
<Binding name="HttpIn" endpointName="HttpIn" />
</Bindings>
</Site>
<Site name="Admin" physicalDirectory="../SampleWebsite/Admin">
<VirtualApplication name="Admin" physicalDirectory="../SampleWebsite/Admin">
<Bindings>
<Binding name="HttpsIn" endpointName="HttpsIn"/>
</Bindings>
</Site>
</Sites>
<Endpoints>
<InputEndpoint name="HttpIn" protocol="http" port="80" />
<InputEndpoint name="HttpsIn" protocol="https" port="443" certificate="www.domain.com" />
</Endpoints>
<Certificates>
<Certificate name="www.domain.com" storeLocation="LocalMachine" storeName="My" />
</Certificates>
I am trying to require SSL for the https://www.domain.com/Admin directory. However, this configuration allows connection to this URL without SSL. Is there a way to require SSL on a sub-directory in Azure?
Upvotes: 2
Views: 681
Reputation: 12174
Use breischi's answer if you are using MVC and implement the [RequiresSSL] attribute for any controller and/or action you want to force through SSL. Otherwise, you could also use Url Rewrite to accomplish the task (add rule to web.config):
<rule name="Force HTTPS" enabled="true">
<match url="^.*/Admin/(.*)$" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/Admin/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
Upvotes: 2
Reputation: 7356
If /SampleWebsite/ has all the code for the /Admin/ subdirectory, I don't think there's a way to prevent users from connecting to it with HTTP. I think you have a couple of options here:
Upvotes: 1