1

I am having an issue with my MVC site with routing when three dots are added to the end of the url, the displays shows the standard ASP.Net 404 error but I want it to route to our custom error page.

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /ABC/mattresses/.../

As far as I can tell, it's not even making it to the MVC. I think the server is seeing it as an issue and it is handling it in the way we don't want. I don't know how to fix this so that I can route this url to our custom error page.

Things I've tried:

routes.MapRoute("MyRoute", "abc/{Keyword}", new { controller = "KeywordSearch", action = "Index", Keyword = UrlParameter.Optional});

routes.MapRoute("MyRouteCatchAll", "abc/{Keyword}/{*CatchAll}", new { controller = "Base", action = "NotFound", Keyword = UrlParameter.Optional, CatchAll = UrlParameter.Optional });

routes.MapRoute("CatchAll", "{*catchAll}", new { controller = "KeywordSearch", action = "NotFound" });

I've also tried using the URL rewrite. Perhaps the regex is just wrong.

<rule name="trailingdots" enabled="true" stopProcessing="true">
      <match url="abc/([_0-9a-z-]+)/^([^.]+)$" />
      <action type="Redirect" url="sr/{R:1}/" />
    </rule>

I'm at my wits end. I can't find any information anywhere to handle this situation.

Any help would be much appreciated.

UPDATE: I was able to get a URL Rewrite rule(s) to work

<rule name="RemoveDotsAndSlash" stopProcessing="true">
      <match url="(.*)/.../$" />
      <action type="Rewrite" redirectType="Permanent" url="{R:1}" />
    </rule>
    <rule name="RemoveDots" stopProcessing="true">
      <match url="(.*)/...$" />
      <action type="Rewrite" redirectType="Permanent" url="{R:1}" />
    </rule>

But I would like to get something like this to work, but it still takes me to the generic 404 page:

<rule name="RemoveTrailingDotsAndSlash" stopProcessing="true">
      <match url="^(.*)$" />
      <conditions logicalGrouping="MatchAny">
        <add input="{REQUEST_URI}" pattern="^(.*)/.../$" />
    <add input="{REQUEST_URI}" pattern="^(.*)/...$" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="{R:1}" />
    </rule>

Any ideas on how close I am to getting exactly what I want?

Thanks

Rhonda
  • 985
  • 5
  • 18
  • 32
  • Did you have the custom error in web.config? For example, `` – Win May 04 '16 at 00:34
  • 1
    Possible duplicate of [Dots in URL causes 404 with ASP.NET mvc and IIS](http://stackoverflow.com/questions/11728846/dots-in-url-causes-404-with-asp-net-mvc-and-iis) – NightOwl888 May 04 '16 at 06:11
  • I have tried customErrors in the web.config. It also does not work. I also tried the method suggested in the above link but am now getting "System.Web.HttpException: Failed to map the path" error. – Rhonda May 04 '16 at 16:24

1 Answers1

3

You doesn't need remove it with a pattern. If you add the following tag to web.config, you can use custom errors to redirect to default error page:

<system.web>    
  <httpRuntime relaxedUrlToFileSystemMapping="true"/> 
  <customErrors mode="On" defaultRedirect="error.aspx">
     <error statusCode="404" redirect="notFound.aspx" />
  </customErrors>
    [ ...]
</system.web>

In documentation, the explanation is that setting relaxedUrlToFileSystemMapping = true is equivalent to allow invalid Windows paths in URL, then it redirected to 404 error and we could catch it.

Lara
  • 542
  • 1
  • 4
  • 21