0

I have only 1 controller and have 1 action only in my example like this:

//
// GET: /Home/
public ActionResult Index(string source,string id)
{
    return View();
}

I have 2 routes registered for this action like -:

 routes.MapRoute(
                name: "Default2",
                url: "{source}/{id}",
                defaults: new { controller = "Home", action = "Index" }
            );

            routes.MapRoute(
                name: "Default",
                url: "",
                defaults: new { controller = "Home", action = "Index", source="source1", id = UrlParameter.Optional }
            );

When I call default, it calls Index action, which is OK when I call like this, /source1/12 - it works.

But when I call like this /source1/12.0 - it does not work and shows up 404 ..

Can anyone suggest why is this happening ?

Pragmateek
  • 13,174
  • 9
  • 74
  • 108
user3359453
  • 349
  • 3
  • 16

3 Answers3

0

It's probably interpreting the .0 as a file extension, and thus looking for a file on disk. Can you replace "." with "_" for the purposes of redirection, and replace back in your action method? Otherwise, you have to look at ways you can get the routing not to interpret ".0" as a file extension. Not sure exactly how off of the top of my head...

MVC routes errors like this to special methods. One is in the controller: HandleUnknownAction, which is called when the action can't be matched. You can override it and handle the action (logging it, etc.) there.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
0

Check this article, it has a solution for you:

From the link:

<configuration>
  <system.web>
    <httpRuntime relaxedUrlToFileSystemMapping="true"/>

    <!-- ... your other settings ... -->
  </system.web>
</configuration>
Cacho Santa
  • 6,846
  • 6
  • 41
  • 73
0

change the ROuteCOnfig to:

routes.MapRoute(
            name: "Default2",
            url: "{source}/{id}/",
            defaults: new { controller = "Home", action = "Index" }
        );

Should solve your issue.

You can also check this SO Thread

Community
  • 1
  • 1
Arijit Mukherjee
  • 3,817
  • 2
  • 31
  • 51