我正在使用 URL 重写,以便如果用户重新加载页面,他应该在他重新加载的同一视图中着陆。在某种程度上,我得到了我想要的。我有 3 个目录 Admin 和 Users 以及一个 Root。我已经为所有三种情况编写了重写规则。单独所有三个都工作正常,即如果我一次使用一个,它适用于相应的目录,但如果尝试在其他目录中重新加载页面,则 url 保持不变,但呈现的页面来自另一个目录。例如,我在用户目录下打开了一个页面,加载的视图是 myprofile,所以现在如果我首先保留用户目录的规则,它将正常工作,但在这种情况下,假设我在管理员下,那么如果我重新加载 url 将是相同的但呈现的页面将是用户的默认页面,但加载的视图将来自管理员。其他情况也会发生同样的事情。以下是我的规则
<rule name="Admin Redirect Rule" stopProcessing="true">
<match url="/(Admin)*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/Admin/Admin.aspx" />
</rule>
<rule name="User Redirect Rule" stopProcessing="true">
<match url="/(Users)*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/Users/User.aspx" />
</rule>
我无法弄清楚我哪里出错了。因为单独而言,这两个规则都运行良好。但是当两者都包括在内时。尽管加载的视图是正确的,但呈现的基本页面正在发生变化。下面是我的目录结构
Root
----Users
-----User.aspx
----Admin
-----Admin.aspx
任何帮助将不胜感激。谢谢!