0

我需要在 IIS 7.5 中使用虚拟目录创建的所有重定向 URL 的列表。

大概使用 appcmd,理想情况下输出如下内容:

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

非常感激!

4

1 回答 1

0

所以我猜这对于 appcmd 是不可能的。我直接查询了 IIS 配置文件(幸运的是,重定向是在此处配置的,而不是在单个文件夹 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"),   
  };
于 2011-08-25T08:21:31.410 回答