对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;
}
}
}

相关文章:

  • 2022-01-18
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2021-11-08
  • 2021-09-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-07-27
相关资源
相似解决方案