0

I'm terrible at regex, but anybody can help here. We have redirect all path to one method but we don't want it if path has any images extension.

I have tried but current code is totally fail.

           routes.MapRoute(
                name: "DefaultCMS",
                url: "{*paths}",
                defaults: new
                {
                    controller = "Home",
                    action = "Index",
                    paths = UrlParameter.Optional
                },
                constraints: new { paths = @".*\.(jpeg|gif|jpg|png)(/.)?)" } // this regex only allow if path has this extension.
            );
Kd Nimavat
  • 282
  • 1
  • 11

1 Answers1

0

Edit: to match the opposite of a pattern refer to this SO question

This regex should match any string that ends with ".{extension}" where {extension} is placeholder for one of the extensions you listed:

^.*\.(jpeg|gif|jpg|png)$

Eldar S
  • 579
  • 3
  • 17