我有一个 Azure 网站,托管一组用于 Windows Phone 应用程序中的动态磁贴的图像
Live Tile 图像请求在 URL 中对比例(和其他)数据进行编码,如下所示(我认为,这方面的文档非常缺乏)
http://example.com/Images/sunny.png?ms-scale=100&ms-contrast=standard&ms-lang=en-us
我想将其重写为
http://example.com/Images/sunny.scale-100.png
其中 .scale-xxx 值与查询字符串中的值匹配
最佳答案
我经过大量搜索后发现了
<system.webServer>
<rewrite>
<rules>
<rule name="SpecificRewrite" stopProcessing="true">
<conditions>
<add input="{QUERY_STRING}" pattern=".*ms-scale=(\d+).*" />
</conditions>
<match url="^Images/(.*).png.*" />
<action type="Rewrite" url="/Images/{R:1}.scale-{C:1}.png" />
</rule>
</rules>
</rewrite>
</system.webServer>
这会将查询字符串添加到匹配项中(引用为 C:1 的组)
<add input="{QUERY_STRING}" pattern=".*ms-scale=(\d+).*" />
这是实际比赛(引用组为 R:1)
<match url="^Images/(.*).png.*" />
这是重写规则
<action type="Rewrite" url="/Images/{R:1}.scale-{C:1}.png" />
有用的引用
您可以在 Azure 网站管理门户的配置部分中打开失败请求跟踪,文件最终位于 /LogFiles/<SiteName>/
关于c# - 如何使用查询字符串中的数据重写 Azure 图像 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24872423/