How to remap username links to different locations based on page address?
-
10-12-2019 - |
Question
On this page I found out how to remap username links to custom pages.
However, I on certain pages I need to remap to an administrator's user info page. How can I modify the url rewrite rule to accomodate this?
I have two rules here - one for regular users and one for admin, which is based on which page is being used as the source. So, I want the admin links for just certain pages, and any other page should go to the user page instead.
But using what I have here breaks the entire site.
Here is the rule:
<rule name="Admin Info Link" enabled="true" stopProcessing="true">
<match url="^(.*/)?_layouts/userdisp.aspx$" />
<action type="Redirect" url="/SitePages/user.aspx?userID={C:1}" appendQueryString="false" />
<conditions trackAllCaptures="true">
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="*/whatsite/whatpage*" />
<add input="{QUERY_STRING}" pattern="ID=(\d+)" />
</conditions>
</rule>
<rule name="User Info Link" enabled="true" stopProcessing="true">
<match url="^(.*/)?_layouts/userdisp.aspx$" />
<action type="Redirect" url="/SitePages/user.aspx?userID={C:1}" appendQueryString="false" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="ID=(\d+)" />
</conditions>
</rule>
How do I do this correctly?
Solution
It could be accomplished by specifying more narrow match pattern for url
For example, let's discuss the scenario, where requests from:
http://{ServerName}/_layouts/teamsiteA/userdisp.aspx?ID=1
should be redirected to:
http://{ServerName}/SitePages/UserInfoA.aspx?userID=1
and requests from:
http://{ServerName}/_layouts/teamsiteB/userdisp.aspx?ID=1
should be redirected to:
http://{ServerName}/SitePages/UserInfoB.aspx?userID=1
XML Rules declaration for that case may look like this:
<rule name="Team Site A User Info Link" stopProcessing="true">
<match url="^(.*/)?teamsiteA/_layouts/userdisp.aspx$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="ID=(\d+)" />
</conditions>
<action type="Redirect" url="/SitePages/UserInfoA.aspx?userID={C:1}" appendQueryString="false" />
</rule>
<rule name="Team Site B User Info Link" enabled="true" stopProcessing="true">
<match url="^(.*/)?teamsiteB/_layouts/userdisp.aspx$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="ID=(\d+)" />
</conditions>
<action type="Redirect" url="/SitePages/UserInfoB.aspx?userID={C:1}" appendQueryString="false" />
</rule>