2011-08-24 110 views

回答

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"), 
    };