应该是HttpRedirect 属性吧,参考
Redirecting in a Script Using the HttpRedirect Metabase Property
http://msdn.microsoft.com/en-us/library/ms525728(v=vs.90).aspx
Redirecting in a Script Using the HttpRedirect Metabase Property
http://msdn.microsoft.com/en-us/library/ms525728(v=vs.90).aspx
我手动在iis里面建立了一个http301重定向的站点,可是我遍历输出的属性里面没有HttpRedirect
DirectoryEntry _entry = new DirectoryEntry("IIS://localhost/W3SVC");
DirectoryEntries _entries = _entry.Children;
foreach (DirectoryEntry _cen in _entries)
{
PropertyCollection props = _cen.Properties;
foreach (string prop in props.PropertyNames)
{
PropertyValueCollection values = props[prop];
foreach (object o in values)
{
Console.Write(prop + ": ");
Console.WriteLine(o.ToString());
}
}
}
Console.ReadLine();
是代码写错了吗测试结果图片:(遍历输出的属性里面没有HttpRedirect)
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetWebConfiguration("http301"); ConfigurationSection httpRedirectSection = config.GetSection("system.webServer/httpRedirect");
httpRedirectSection["enabled"] = true;
httpRedirectSection["destination"] = @"http://www.crcz.cn";
httpRedirectSection["exactDestination"] = true;
httpRedirectSection["httpResponseStatus"] = @"Permanent"; serverManager.CommitChanges();
}