0
我需要使用IIS 7.5中的虚拟目录创建的所有重定向URL的列表。列出IIS站点中的所有虚拟目录重定向
据推测使用APPCMD,最好outputing是这样的:
/foo http://example.com/blah
/bar http://another.example.com/ 301
非常感谢!
我需要使用IIS 7.5中的虚拟目录创建的所有重定向URL的列表。列出IIS站点中的所有虚拟目录重定向
据推测使用APPCMD,最好outputing是这样的:
/foo http://example.com/blah
/bar http://another.example.com/ 301
非常感谢!
所以我想这不适用于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"),
};