Dot at end of URL using MVC4 throws error

RobVious

http://localhost:56472/test. throws the ugly yellow ASP.NET error message - The Resource Cannot be Found.

How do I catch this Request and

  1. Prevent the ugly yellow
  2. Strip the period from the Request and redirect?

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

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using the dot "." character in MVC4 Routes

From Dev

MVC4 Using nested @Html.RenderPartial() throws Compiler Error Message: CS1502

From Dev

Accessing to properties using dot notation in React throws me an error

From Dev

MVC4 Razr throws error on AngularJS email regex pattern

From Dev

Error with dot (.) character in URL

From Dev

Error with dot (.) character in URL

From Dev

MVC4 & AngularJS error when using ngAnimate as a dependency

From Dev

Conversion error (nvarchar to int) for SQL query using MVC4

From Dev

if statement throws error as end of file

From Dev

Redirect to URL throws error

From Dev

Regex right match url with DOT at the end

From Dev

MVC4 section name with dot

From Dev

Asp.Net MVC route action method doesn't call when there is a DOT (.) at the end of url

From Java

Powershell using regEx remove a dot at the end of a string

From Dev

Scraper throws invalid url error

From Dev

Proc throws error when used with do end

From Dev

Using HtmlHelpers in MVC4

From Dev

dot in url returns 404 error (.htaccess)

From Dev

dot in url returns 404 error (.htaccess)

From Dev

How to call Web API action with a dot at the end of the URL?

From Dev

Django Rest Framework using dot in url

From Dev

nodejs - upload using fs.createReadStream, requestjs, streaming and AWS S3 presigned url throws error

From Dev

Mvc4 Model to url querystring

From Dev

Mvc4 Model to url querystring

From Dev

MVC4 Bundle result to an specific url

From Dev

Regex not start with dot or end with dot

From Dev

AngularJs template url loading throws CORS error

From Dev

remove dot from end of word in array using C#

From Dev

Custom Error Handling with MVC4

Related Related

HotTag

Archive