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