Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewriting custom tag attributes using IIS Url Rewrite 2.0 and ARR

I've developed a custom grid control that uses data-* attributes to configure how the grid is supposed to work (in a similar vein to how Bootstrap data API components work. For a particular deployment, I'm having to proxy my web application into another web application using IIS and Application Request Routing (ARR) + URL Rewrite. The proxying part is all done, I'm currently trying to configure the outbound rules for rewriting urls to match. For instance, I currently have rules set up such as:

  • Rewrite HTTP redirects by updating the Location: header.
  • Rewrite Html content for URIs in standard tags (e.g., A, Area, base, etc.)
  • Rewrite Css content for URI's that are relative (e.g. /cassette.axd -> /blog/cassette.axd).

The last issue I am having, is getting the URL rewrite module to accept my urls in data attributes, e.g., if my grid is such like:

<table data-grid data-query="/api/users/">

Should be rewritten as

<table data-grid data-query="/blog/api/users/">

I stress that all other tags, such as <a href and <img src work as expected and even a custom <property value tag is correctly rewritten. Just seems to by hypenated attributes.

I've tried adding a <customTags> section, with my custom tags in:

<customTags>
    <tags name="Bootgrid">
        <tag name="table" attribute="data-query" />
        <tag name="table" attribute="data-update" />
        <!-- This next tag WORKS -->
        <tag name="property" attribute="value" />
    </tags>
</customTags>

However, the above is not matching any attributes that have a hyphen. Not sure if this is actually solvable or not because I can't see anything in IIS configuration to set these.

Also annoyingly once you've created a set of Custom Tags in IIS, you can't seem to edit them again. :-/

like image 207
Matthew Abbott Avatar asked Nov 03 '22 21:11

Matthew Abbott


1 Answers

I had the same issue, and it appears (although not confirmed by Microsoft) that IIS cannot handle a custom tag that contains a -

A work around that worked for me was to use another outbound Rule. In this example I am attempting to replace the data-zoom-image attribute within an img tag (You will need to replace the &lt;img with &lt;table and data-zoom-image with data-query in both the "match" and "action"

<rule name="RewriteRelativePathsCustomTags1" preCondition="IsHtml" enabled="true">
    <match filterByTags="None" pattern="&lt;img ([^>]*)data-zoom-image=&quot;(.*?)&quot;([^>]*)>" />
    <action type="Rewrite" value="&lt;img {R:1}data-zoom-image=&quotYOUR VALUE TO REWRITE i.e /blog{R:2}&quot;{R:3}>" />
</rule>
<preConditions>
    <preCondition name="IsHtml">
        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
    </preCondition>
</preConditions>

Hope this helps

like image 166
aRJeLA Avatar answered Nov 09 '22 15:11

aRJeLA