在asp.net 4.5.2(web api)中,我想拥有它,以便对于任何Web请求(不是api),如果它不指向任何文件(即会导致404),它应该只是返回根页面(“/”),但不更改链接,链接应该仍然是我键入的内容。
如何在web.config中设置它?
您可以使用以下规则,如果文件或目录不存在,它将重写页面。它只会重写页面网址将是相同的。
<rule name="Rewrite to index" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="http://www.sample1.com/index.html" logRewrittenUrl="true" />
</rule>
此致,Jalpa。