MVC4 project – cannot have dot in parameter value?

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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>

Method 2

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

Method 3

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x