对webapi1,找了好久没看见比较好的获取Access-Control-Allow-Origin值的方法,多方搜索后,提出下面一种,至少可以完成目标:
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection cs = webConfig.GetSection("system.webServer") as ConfigurationSection;
bool haveOriginInInWebConfig = false;
if (cs != null)
{
XDocument xml = XDocument.Load(new StringReader(cs.SectionInformation.GetRawXml()));
foreach (XElement e in xml.Descendants("add"))
{
if(e.FirstAttribute.Value.Equals("Access-Control-Allow-Origin"))
{
haveOriginInInWebConfig = true;
break;
}
}
}