c# - How to figure out what IIS Express instance is using a port? -


i want kill running iis instance programmatically occupying specific port, seems there no way figure out iis instance using specific port.

netstat.exe shows process having pid 4, that's system process. "netsh http show urlacl" not display occupied port @ all.

the iis express tray program knows somehow. when try start iis express instance while port occupied following error:
"port '40000' being used process 'iis express' (process id '10632').

anyone got clue how can information?

it seems pid 4 (system) because actual listening socket under service called http.

i looked @ iisexpresstray.exe using provide list of running iisexpress applications. thankfully it's managed .net code (all in iisexpresstray.dll) that's decompiled.

it appears have @ least 3 different ways of getting port number process:

  1. reading /port command-line arguments (unreliable know)
  2. running netsh http show servicestate view=requestq , parsing output
  3. calling microsoft.web.runtimestatusclient.getworkerprocess(pid) , parsing site url

unfortunately, of useful stuff in iisexpresstray.dll iisexpresshelper class declared internal (although imagine there're tools generate wrappers or copy assembly , publicize everything).

i opted use microsoft.web.dll. in gac, though reason wasn't appearing in list of assemblies available add reference in visual studio, copied file out gac. once had microsoft.web.dll matter of using code:

    using (var runtimestatusclient = new runtimestatusclient())     {       var workerprocess = runtimestatusclient.getworkerprocess(process.id);       // apparently iisexpress process can run multiple sites/applications?       var apps = workerprocess.registeredurlsinfo.select(r => r.split('|')).select(u => new { sitename = u[0], physicalpath = u[1], url = u[2] });       // if assume 1 app       return new uri(apps.firstordefault().url).port;      } 

you can call runtimeclient.getallworkerprocesses retrieve actual worker processes.

i looked registeredurlsinfo (in microsoft.web.dll) , found it's using 2 com interfaces,

  1. irsca2_core (f90f62ab-ee00-4e4f-8ea6-3805b6b25cdd)
  2. irsca2_workerprocess (b1341209-7f09-4ecd-ae5f-3ee40d921870)

lastly, read version of microsoft.web.administration apparently being able read iisexpress application info, information scarce, , 1 found on system wouldn't let me instantiate servermanager without admin privileges.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -