views:

256

answers:

2

I have web services built with ASP.NET and ASP.NET clients consuming them. When consuming the webservices, how would I to force the clients to use https?

I don't want to force the whole site to use https by turning on require SSL in IIS.

Can I use the IIS7 URL rewrite module to re-route http requests to https?

+2  A: 

No, you cannot use URL rewriting to change the protocol.

Instead, you could just implant a check in your web service and throw an exception if the protocol is HTTP.

Fyodor Soikin
+2  A: 

Any chance you can add your webservices to a virtual directory and just force the virtual directory to use SSL? Along with checking inside the webservice calls as Fyodor suggest, you could add a check in Application_BeginRequest in your global.asax, although it's not very tidy:

void Application_BeginRequest(object sender, EventArgs e)
{
     if (!Request.IsSecureConnection && Request.Url.ToString().Contains(".asmx"))
     {
        string secureUrl = Request.Url.ToString().Replace("http:", "https:");
        Response.Redirect(secureUrl);
     }
}
Chris Pebble
I tried looking for a way to set Requires SSL for a virtual directory, but in IIS 7.5, it looks like you can only do it for the site, please correct me if I'm wrong.
Steve
Take a look at this technet article. It appears you can specify require ssl down to the individual page level: http://technet.microsoft.com/en-us/library/cc732367(WS.10).aspx
Chris Pebble