Freigeben über


URL Rewrite 2.0 Rule can prevent Images from displaying on WebControls like TreeView

I was excited to try URL Rewrite to create some rules on my internal web site.  I added a rule to map a query string like https://mysite/treepage.aspx?nodeName=RedColors to https://mysite/RedColors .  After doing this I found that the images of the treeview web control now did not display.  I enabled FREB tracing and found that this rule was translating webresource.axd improperly:

<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
  <match url="^([^/]+)/?$" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />

RequestURL    https://mysite:80/WebResource.axd?d=zGZU6qcW6fzAgYe-oI85v1qoiSgWelpv1EkImgNZdKA1&t=633802488069218315

RequestURL    https://mysite:80/treepage.aspx?nodeName=WebResource.axd&d=zGZU6qcW6fzAgYe-oI85v1qoiSgWelpv1EkImgNZdKA1&t=633802488069218315

Since the rule saw the ‘?’ char it was trying to map it.

To solve this add a rule to exclude processing of .axd files:

<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
  <match url="^([^/]+)/?$" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <!--  The following condition prevents rule from rewriting requests to .axd files -->
    <add input="{URL}" negate="true" pattern="\.axd$" />
  </conditions>

 

Please let me know if you found this Post useful and if it solved your problem!