使用以下规则,我可以成功重写url以重定向到app/index.cshtml。有些资源,如图片、css和javascript不应该被重定向,所以我使用了条件:
<rule name="AngularJS">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" negate="true" pattern=".png$" />
<add input="{URL}" negate="true" pattern=".css$" />>
<add input="{URL}" negate="true" pattern=".js$" />
</conditions>
<action type="Rewrite" url="app/index.cshtml" />
</rule>
但是一旦我开始使用缩小的内容,请求的URL就变得类似于:
/myapp/包/公用事业吗?v = EH9YuZDBt_fj7iqRP2QA8lCkJ59wjV6woELIwvR7irk1
如何防止这种类型的url被重定向
你可以创建一个忽略规则,匹配url来忽略
<rule name="Ignore" enabled="true" stopProcessing="true">
<match url="^(images|css|bundles).*"/>
<conditions logicalGrouping="MatchAll" trackAllCaptures="false"/>
<action type="None"/>
</rule>