0

I was using a routing pattern. Recently, I've changed the pattern. Now, I'm struggling with an issue that annoys me.

I'd like to catch the following URL:

http://www.mysite.com/news_title/-1322.html

routing pattern:

    routes.MapRoute(
                    name: "haber2",
                    url: "{noFollow}-{id}.html",
                    defaults: new { controller = "Anasayfa", action = "HaberID" },
                    constraints: new {id = "\\d+"}
                );

While clicking the link below, I'm facing with not found. How to overcome this problem?

Any helps, tricks is very appreciated.

Ronald Wildenberg
  • 31,634
  • 14
  • 90
  • 133
Mesut
  • 1,845
  • 4
  • 24
  • 32

2 Answers2

0

You're missing a slash in your url:

 routes.MapRoute(name: "haber2",
                url: "{noFollow}/-{id}.html",
                defaults: new { controller = "Anasayfa", action = "HaberID" },
                constraints: new {id = "\\d+"}
            );
Mister Epic
  • 16,295
  • 13
  • 76
  • 147
  • Please mind that 'news_title/' come from database. Also 'news_title' may come from database. So routing pattern cannot be changed. – Mesut Jan 30 '14 at 12:19
  • Ok, then why don't you simply map another route to satisfy the other case? – Mister Epic Jan 30 '14 at 12:31
  • yes this is a solution and I did by rewrite engine. But this is not the right answer for my question, thanks. – Mesut Feb 02 '14 at 11:41
0

No. Not possible.

Slash in route will definitely create this problem. Default Routing engine always searches routing pattern based on no. of slashes in URL.

I tried it with wild card character '*' like catch all routes.

something like following.

 routes.MapRoute(
                    name: "haber2",
                    url: "{noFollow*}-{id}.html",
                    defaults: new { controller = "Anasayfa", action = "HaberID" },
                    constraints: new {id = "\\d+"}
                );

but without luck..

Hope helps.

Dipal Mehta
  • 440
  • 6
  • 20