c# - 如何使用查询字符串中的数据重写 Azure 图像 URL

标签 c# azure url-rewriting live-tile

我有一个 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/

相关文章:

c# - 划掉文字文本

python - 为什么 Azure DevOps Server 交错输出

apache - 如何使用 Apache mod_rewrite 隐藏 .html 扩展名

c# - XNA 基本画图程序

c# - 将指向类的指针从 C# 传递到非托管 C++ 代码

c# - 套接字与 Wcf 通信

使用企业库在 azure 中记录异常

azure - 在最佳时间运行不同的后台作业

asp.net - IIS7 : URL rewrite http://web1. com/web1/def.aspx 到 http ://web1. com/def.aspx

apache - 301 重定向不适用于索引文件