views:

179

answers:

1

Hello,

I need some web.config examples for each expression types below :

$number

The last substring matched by group number number.

$<name>

The last substring matched by group named name matched by (?< name > ).

${property}

The value of the property when the expression is evaluated.

${transform(value)}

The result of calling the transform on the specified value.

${map:value}

The result of mapping the specified value using the map. Replaced with empty string if no mapping exists.

${map:value|default}

The result of mapping the specified value using the map. Replaced with the default if no mapping exists.

Sample:

<rewriter>
    <if url="/tags/(.+)" rewrite="/tagcloud.aspx?tag=$1" />
    <!-- same thing as <rewrite url="/tags/(.+)" to="/tagcloud.aspx?tag=$1" /> -->
</rewriter>

Thank you very much !

+1  A: 

Here's what I found/guessed. Not tested.

$number : http://urlrewriter.net/index.php/support/using

<rewrite url="^(.*)/(\?.+)?$" to="$1/default.aspx$2?" />

$1 matches (.*)
$2 matches (\?.+)

$< name > : this one I'm not so sure on the regex, couldn't find anything in documentation

<rewrite url="^(?<group1>(.*))/(\?.+)?$" to="$<group1>/default.aspx$2?" />

$<group1> matches 

${property} : http://urlrewriter.net/index.php/support/reference/actions/set-property

<set property="branch" value="$3" />
<rewrite to="/showbranch.aspx?branch=${branch}" />

${transform(value)} : http://urlrewriter.net/index.php/support/reference/transforms

<set property="transform-name" value="lower" />
<set property="value-to-transform" value="THIS WAS UPPER CASE" />

<redirect to="/WebForm1.aspx?q=${encode(${${transform-name}(${value-to-transform})})}" />

results in "/WebForm1.aspx?q=this+was+upper+case"

${map:value} : http://urlrewriter.net/index.php/support/reference/transforms/static

<mapping name="areas">
    <map from="sydney" to="1" />
    <map from="melbourne" to="2" />
    <map from="brisbane" to="3" />
</mapping>

<rewrite to="/area.aspx?area=${areas:$3}" />

results in "/area.aspx?area=brisbane"

${map:value|default}

<mapping name="areas">
    <map from="sydney" to="1" />
    <map from="melbourne" to="2" />
    <map from="brisbane" to="3" />
</mapping>

<rewrite to="/area.aspx?area=${areas:$4|perth}" />

results in "/area.aspx?area=perth"
Jonathan