不久前,我设计了一款应用程序,可以在我的页面中插入一个meta标签,这样我就可以在不同的文档模式下用internet explorer测试它们。我的解决方案,虽然功能强大,但却是笨拙的。假设IIS7和explorer作为服务器/客户端,有哪些轻量级的解决方案可以在短时间内以编程方式快速添加元标记?
发布于 2013-04-19 17:01:41
您可以很容易地使用URL Rewrite并利用出站重写功能来实现这一点。安装完成后,只需添加一个web.config到应用程序文件夹,如下所示,它会自动在应用程序提供的每个HTML页面中插入一个元标记。显然,您可以添加更多条件,使其仅针对您想要的页面进行重写(请参见preConditions),以及从头部或其他位置捕获数据并将其添加到响应中。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<outboundRules rewriteBeforeCache="true">
<rule name="WriteMETA" preCondition="MatchHTML">
<match pattern="<head>" occurrences="1" />
<action type="Rewrite" value="<head>
<meta name='author' content='Carlos Aguilar Mares' />
" />
</rule>
<preConditions>
<preCondition name="MatchHTML" patternSyntax="Wildcard">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
https://stackoverflow.com/questions/16108194
复制