Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine bindings from IIS hosting environment

I would like to retrieve the bindings of a running IIS application directly from the context of the applications running code.

I've explored System.Web.Hosting.HostingEnvironment, but from there I can only access properties like SiteName etc.

What I need is the host string part of the binding. Like "app.mydomain.com".

Is that possible? A simple "Yes" or "No" with a msdn reference will suffice as an answer.

like image 949
marko Avatar asked Nov 30 '25 09:11

marko


1 Answers

You might not be able to get to bindings from IIS config unless you're elevated (and you shouldn't run elevated) but you should be able to get the host part of the binding from:

Request.ServerVariables["URL"];

From there you can load it into the URI class and get the host portion.

Be aware however that it's the url that the request came in on. If you have multiple bindings in the IIS config you won't get those.

like image 122
bryanmac Avatar answered Dec 01 '25 23:12

bryanmac