当 URL 以点结尾时重定向到自定义 404 页面

Redirect to a Custom 404 Page When the URL ends with Dot

在我的 web.config 文件中,我将此规则设置为重定向到自定义 404 页面,它适用于实际上不存在的 URL。

<system.webServer>
    <httpErrors existingResponse="Auto" errorMode="Custom">
        <remove statusCode="404" subStatusCode="-1"/>
        <error statusCode="404" path="/CustomErrors.aspx" responseMode="ExecuteURL"/>
    </httpErrors>
</system.webServer>

我的问题是 URL 以 Point(.) 字符结尾。例如

http://192.168.1.151/login.

http://192.168.1.151/login....

这会导致以下错误:

Server Error in '/' Application.
The resource cannot be found.

Whosebug 很好地处理了这个问题: 404 page in Whosebug

任何建议都可能有所帮助。

在 httpRuntime 部分添加此属性有帮助:

<configuration>
  <system.web>
    <httpRuntime ... relaxedUrlToFileSystemMapping="true" .../>
  </system.web>
</configuration>

Gets or sets a value that indicates whether the URL in an HTTP request is required to be a valid Windows file path.

有关relaxedUrlToFileSystemMapping

的更多信息