【问题标题】:List all virtual directory redirects in an IIS site列出 IIS 站点中的所有虚拟目录重定向
【发布时间】:2011-08-24 12:06:07
【问题描述】:

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

大概使用appcmd,理想情况下输出类似:

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

非常感谢!

【问题讨论】:

    标签: iis iis-7.5 appcmd


    【解决方案1】:

    所以我猜这对于 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-02-12
      • 1970-01-01
      • 1970-01-01
      • 2012-10-24
      • 1970-01-01
      • 2011-09-19
      • 1970-01-01
      • 2017-03-17
      • 1970-01-01
      相关资源
      最近更新 更多