0

I have a fairly simple setup where I am creating a MVC website to display the details of a customer. For customers the unique id is their email address which is non-numeric. So in my ROuteConfig.cs I have the default route

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

In my controller called "CustomerController" I have this action

public ActionResult Details(string id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            CustomerModel customerModel = _customerManager.GetCustomer(id);
            if (customerModel == null)
            {
                return HttpNotFound();
            }
            return View(customerModel);
        }

Now when I navigate to this url

http://localhost:45826/customer/Details/someemail%40web.com

the routing infrastructure does not invoke the Action "Details" on my controller, however if I navigate to this url

http://localhost:45826/customer/Details/5

then the action is invoke passing in the value 5 for the id parameter.

If I change the URL a bit and use this syntax

http://localhost:45826/customer/Details?id=fromweb%40web.com

Again the action is invoked properly passing the email address to the id parameter.

Can someone help understand why non-numeric values aren't mapping to the action as expected?

I have also tried adding this route before the default route but that doesn't work too and I get same results

routes.MapRoute(
            name: "ViewCustomer",
            url: "customer/details/id",
            defaults: new { controller = "Customer", action = "Details", id = "" }
            );
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Nikhil
  • 3,304
  • 1
  • 25
  • 42
  • 6
    The `.` in your url is the problem. Check this http://stackoverflow.com/questions/11728846/dots-in-url-causes-404-with-asp-net-mvc-and-iis – Dandy Dec 22 '15 at 12:44
  • 1
    +1 because IIS thinks this is an extension and the request never even reaches ASP.NT. As a comment in the linked answer shows, a simple `/` at the end is enough to pass the URL to ASP.NET MVC – Panagiotis Kanavos Dec 22 '15 at 12:49

1 Answers1

0

Add this in web.config:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">

Read: https://stackoverflow.com/a/49831093/10299573

L.Zoffoli
  • 129
  • 3
  • 10
  • Using that directive has a rather significant impact on the ASP.NET pipeline. It is like using a sword to kill a fly and hence IMHO is not the right and optimal solution for this problem. – Nikhil Oct 23 '18 at 22:01