http://localhost:56472/test.
throws the ugly yellow ASP.NET error message - The Resource Cannot be Found
.
How do I catch this Request and
I do have this in my Global.asax
:
protected void Application_Error(object sender, EventArgs e) {
// Do whatever you want to do with the error
}
But the error is not being caught. Normal 404s are caught here and I redirect to my custom error page successfully.
I'm deploying to Azure PaaS so not much granular control over IIS.
Update: My attempt at rewrite:
<rule name="Strip Periods" stopProcessing="true">
<match url="^(.*[^.])(\.+)$" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^site.com$" />
</conditions>
<action type="Redirect" url="{MapProtocol:{HTTPS}}://www.site.com/{R:1}" />
</rule>
You need two steps to do this. First, a rewrite rule to handle the redirection:
<rule name="RemoveTrailingDot" stopProcessing="true">
<match url="(.*)\.+$" />
<action type="Redirect" url="{R:1}" />
</rule>
Secondly, the following directive (found in this related answer)
<system.web>
<httpRuntime relaxedUrlToFileSystemMapping="true"/>
</system.web>
The comments on the related answer suggest it doesn't always work, but it's working for me on IIS on Windows 10.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments