0

I have 3 links on my website that are generated like below using url.action()

<a href="/ViewAd/421/Honda-Accord-2.4-Executive-Automatic" >

<a href="/ViewAd/420/Renault-Sandero-900t-Dynamique" >

<a href="/ViewAd/419/Audi-Rs5-2.9-Tfsi-Quattro-Tiptronic" >

As you can see, the links are exactly the same except for the IDs and the descriptions that are different. Oddly the only one that works properly is the 2nd ad, if I click on the 1st or the 3rd ad the request fails with a 404 error, also while debugging locally the 1st and 3rd ads don't even hit the breakpoint on my controller action as per below. What could be the problem?

I have attribute routing enabled and this is what my controller action looks like

[Route("ViewAd/{adID}/{desc}")]
public ActionResult ViewSingleAd(int adID, string desc)
{
   // Code removed for brevity

   return View();
}

My RouteConfig.cs is as follows

namespace myApp
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapMvcAttributeRoutes();

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

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

        }
    }
}
ShatterStar
  • 99
  • 1
  • 1
  • 7
  • Tried to remove the . from the links? – andreasnico May 09 '19 at 07:37
  • 1
    Hi, I've figured that out now, it is actually the dots in the url that are causing it to break, I am currently trying to find a solution, if you have one please tell me about it – ShatterStar May 09 '19 at 08:22
  • To be honest, I think I would just replace the dot with an - in the method that's generating the url's (if you have any control over that). – andreasnico May 09 '19 at 11:41

1 Answers1

0

This may be because IIS is trying to locate the static resource in the server because of the dot.

Add the following line to your site's web.config within the system.webServer / handlers element:

<add name="ApiURIs-ISAPI-Integrated-4.0"
     path="/people/*"
     verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
     type="System.Web.Handlers.TransferRequestHandler"
     preCondition="integratedMode,runtimeVersionv4.0" />

Check this and this to know more options to resolve this.

Shaiju T
  • 6,201
  • 20
  • 104
  • 196