gpt4 book ai didi

c# - 如何在 C# 中读取带有 .net 4 的 IIS7 上的 web.config 的一部分

转载 作者:行者123 更新时间:2023-11-30 12:16:35 25 4
gpt4 key购买 nike

我的 web.config 中有以下部分:

<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="0.00:00:30" />

<remove fileExtension=".ogv" />
<mimeMap fileExtension=".ogv" mimeType="video/ogg" />

<remove fileExtension=".webm" />
<mimeMap fileExtension=".webm" mimeType="video/webm" />

<!-- and a bunch more... -->
</staticContent>
<!-- ... -->
</system.webServer>

这是我在伪代码中尝试做的事情:

var ext = ".ogg";
var staticContentElements = GetWebConfig().GetSection("system.webServer/staticContent").ChildElements;
var mimeMap = staticContentElements.Where(c =>
c.GetAttributeValue("fileExtension") != null &&
c.GetAttributeValue("fileExtension").ToString() == ext
).Single();

var mimeType = mimeMap.GetAttributeValue("mimeType").ToString();

基本上,我需要通过 fileExtension 搜索 mimeMap 并获取它们的 mimeType。

最佳答案

您需要create a custom configuration section获取该信息。

关于c# - 如何在 C# 中读取带有 .net 4 的 IIS7 上的 web.config 的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5098406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com