5

I have an MVC4 project, and I am trying to get it working on URLs like /QRCode/address/amount. Here's how it is declared:

Route:

routes.MapRoute(
    name: "QRCode",
    url: "QRCode/{address}/{amount}",
    defaults: new { controller = "QRCode", action = "Index" }
);

Controller:

public class QRCodeController : Controller
{
    public ActionResult Index(string address, double amount)
    {
         ...

The problem is:

When URL is: QRCode/address1/33, all works fine, but if there is a dot in second parameter, such as: QRCode/address1/33.33, I am getting a "HTTP Error 404.0 - Not Found".

Re-declaring second parameter a string yields same result.

Using %2E in lieu of a dot yields same result

Anybody knows what is going on here? I know it worked fine in MVC3

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
galets
  • 17,802
  • 19
  • 72
  • 101
  • 1
    "dots" usually trigger IIS to try and map the file to a MIME type, then to a handler. So IIS is probably looking for a .33 handler, which of course doesn't exist. Is your web.config configured to run all requests through the pipeline? – vcsjones Dec 16 '12 at 19:39
  • I would check handler mappings.. – Baz1nga Dec 16 '12 at 19:40

3 Answers3

7

if this is on IIS 7, then add this to your config file and it should work fine:

<system.web>
     <httpRuntime relaxedUrlToFileSystemMapping="true" />
</system.web>
kabaros
  • 5,083
  • 2
  • 22
  • 35
  • I tested, and it does indeed do the trick. Apparently, what changed was not MVC version, but rather runtime. My httpRuntime tag had targetFramework="4.5", this is what caused the issue. relaxedUrlToFileSystemMapping fixed it. – galets Dec 17 '12 at 03:46
6

Yes... See comments, the handler mapping was a problem.

I changed URL from QRCode/address1/33.33 to QRCode/address1/33.33/ and mapping worked fine

galets
  • 17,802
  • 19
  • 72
  • 101
0

Here's another option: don't map the amount but pass it as a URL parameter with name:

routes.MapRoute(
    name: "QRCode",
    url: "QRCode/{address}",
    defaults: new { controller = "QRCode", action = "Index" }
);

now call the api with such an url:

http://<server>/QRCode/address1?amount=33.33
Sten Petrov
  • 10,943
  • 1
  • 41
  • 61