tags:

views:

91

answers:

4

I have an ASP.NET application. I want to redirect to the secure port for the site, but the site may not necessarily be using the default of 443. Is there some environment variable or API call I can make to determine the currently configured SSL port for a site?

Thanks!

+1  A: 

I asked a similar question here. So far, I didn't find a solution. If you had admin rights, you could use any number of Microsoft.Web.Administration, WMI or whatever to do it... but inside the web app I didn't find anything

chris166
A: 

I'm almost totally ignorant of how ASP.NET works, but in general, there's no guarantee that there will be an SSL port. There could be none, there could be 5... I think you'll have to provide this info to your app through some sort of config file. My apologies if this is not relevant for ASP.NET.

rmeador
A: 

Can't you use this re-direction technique?

Magnus Johansson
+1  A: 

If you don't know this port number upfront and it can't stored somewhere known (such as your web.config) you'd need to be able to query the IIS metabase to get the SecureBindings attribute of the site's IIsWebServer node.

There are a few ways to accomplish this, such as using the System.DirectoryServices namespace, but all of them require Full Trust or elevated permissions.

Kev
True, but it's probably simplest to add the magic number of the port to web.config and expect the admins to configure it correctly. Then you do a simple redirect.
Steven Sudit
Agreed, but it looked like the OP was trying to work this on the fly.
Kev