如何返回任何未指向IIS web.config中任何文件的Web请求的特定页面?

问题描述 投票:0回答:1

在asp.net 4.5.2(web api)中,我想拥有它,以便对于任何Web请求(不是api),如果它不指向任何文件(即会导致404),它应该只是返回根页面(“/”),但不更改链接,链接应该仍然是我键入的内容。

如何在web.config中设置它?

iis web-config
1个回答
0
投票

您可以使用以下规则,如果文件或目录不存在,它将重写页面。它只会重写页面网址将是相同的。

<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>

enter image description here

此致,Jalpa。

© www.soinside.com 2019 - 2024. All rights reserved.