开发者

List all virtual directory redirects in an IIS site

开发者 https://www.devze.com 2023-03-30 22:45 出处:网络
I need a list of all redirect URLs which have been created with virtual directories in IIS 开发者_Go百科7.5.

I need a list of all redirect URLs which have been created with virtual directories in IIS 开发者_Go百科7.5.

Presumably using appcmd, ideally outputing something like:

/foo  http://example.com/blah
/bar  http://another.example.com/ 301

Much appreciated!


So I guess this isn't possible with appcmd. I queried the IIS configuration file directly (luckily the redirects were configured here and not in individual folder web.configs!).

var config = XElement.Load (@"C:\path\to\applicationHost.config");

var query =
  from location in config.Elements("location")
  let webServer = location.Element("system.webServer")
  where webServer != null
  let redirect = webServer.Element("httpRedirect")
  where redirect != null
  where (string) redirect.Attribute("enabled") == "true"
  let path = (string) location.Attribute("path")
  where !String.IsNullOrWhiteSpace(path)
  orderby path
  select new
  {
       path,
       destination = (string) redirect.Attribute("destination"),
       exactDestination =  (string) redirect.Attribute("exactDestination"),
       childOnly =  (string) redirect.Attribute("childOnly"),
       httpResponseStatus =  (string) redirect.Attribute("httpResponseStatus"),   
  };
0

精彩评论

暂无评论...
验证码 换一张
取 消