我在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>
这是我在psuedo-code中尝试做的事情:
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搜索mimeMaps并获取它们的mimeType.
解决方法:
您需要create a custom configuration section才能获得该信息.
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!