2

Running IIS6.
So, '.' do not work in IIS6, but they work fine in the visual studio debugger and IIS7. Here's the steps to reproduce.

Steps to reproduce:
- Start with a blank MVC 3 project.
- Add A new view called "Index" and accept the defaults.
- Configure RegisterRoutes() as follows:

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

    routes.MapRoute(
        "QuerySomething",
        "QueryStuff/Index/{*aString}",
        new { controller = "QueryStuff", action = "Index", aString = UrlParameter.Optional } // Parameter defaults
    );

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
    );

}

Now, add a controller that returns Json:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

    namespace MvcApplication1.Controllers
    {
        public class QueryStuffController : Controller
        {
            //
            // GET: /QueryStuff/

            public ActionResult Index(string aString)
            {
                return Json("aString:oye",JsonRequestBehavior.AllowGet);
            }

        }
    }
  1. Verify that the page is accessible:

    http://serverName/QueryStuff/Index/someInfo

You should get http 200.

  1. Now try to get there with a '.' in the path

    http://serverName/QueryStuff/Index/someInfo.com

You should get a http 404 error. (Note that this error is NOT reproduceable when running through visual studio debugger. One must deploy the code to IIS.)

UPDATE
I modified Regex to route for email addresses and it made the problem even worse.

    routes.MapRoute(
        "QuerySomething",
        "QueryStuff/Index/{aString}"
        , new { controller = "QuerySomething", action = "Index" },
        new { aString = @"\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b" }
        ); 

With this its 404 everytime.

P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348

2 Answers2

4

I don't think this is an MVC error as such, more a limitation of http? We had the same issues so ended up swapping "." for "!" in URLs then converting them back to "." in the controllers.

Colin Desmond
  • 4,824
  • 4
  • 46
  • 67
  • 1
    This is something I hope to avoid doing. – P.Brian.Mackey Mar 21 '11 at 17:14
  • 1
    @ColinDesmond: I'm not sure where you're going with the "limitation of http" bit. HTTP has no issues with `.` and they're commonly used in URLs and URIs (and Internet-routable domain names require them). Perhaps you meant RegEx or the web server's parsing of `.` in routing rules? – Powerlord Mar 21 '11 at 18:30
  • 1
    @Colin Desmond - I feel confident that the issue has to do with IIS6. Since BuildStarted cannot reproduce the problem on IIS7 combined with the fact this thing works fine in the visual studio debugger. I am using your idea to replace '.' char with '!'. It works great as a workaround until somebody like @Haacked confirms the problem. – P.Brian.Mackey Mar 21 '11 at 19:08
  • 2
    After a bit more poking about, this might help http://stackoverflow.com/questions/294495/semantic-urls-with-dots-in-net – Colin Desmond Mar 21 '11 at 20:02
  • @Colin Desmond - That corrected it. Still amazing that this was only happening in IIS 6. – P.Brian.Mackey Mar 21 '11 at 20:52
  • Actually dangit its still broken. I'm giving up on this and using the '!' trick. – P.Brian.Mackey Mar 21 '11 at 21:54
  • @Colin, I have the same issue. Can you explain how you have applied the "!" trick? have you "rewrite the url" at the start of the request or you produce directly links with the "!" instead of "." in the html? Help is appreciated – Lorenzo Melato Apr 22 '11 at 07:29
  • I'm afraid we do nothing fancy here, we have two properties on a view model, the RealSerial and the UrlSerial, both strings, but the UrlSerial we substitute all ":" for "!". This is the one used in Url's. In our controllers, we simply use a common method to substitute "!" for ":" to get back to the RealSerial. – Colin Desmond Apr 24 '11 at 22:09
1
routes.MapRoute(
    "QuerySomething",
    "QueryStuff/Index/{*aString}",
    new { controller = "QueryStuff", action = "Index", aString = UrlParameter.Optional } // Parameter defaults
);

You forgot the wildcard character in your route. (note aString above) However, one thing to note when using them is that it will also match http://serverName/QueryStuff/Index/something.com/blah/blah/blah/blah The dot is a file extension separator which is why it's not included. You could also do this if you know you'll always have extensions:

routes.MapRoute(
    "QuerySomething",
    "QueryStuff/Index/{aString}.{extension}",
    new { controller = "QueryStuff", action = "Index", aString = UrlParameter.Optional } // Parameter defaults
);
Buildstarted
  • 26,529
  • 10
  • 84
  • 95
  • @BuildStarted - I'm still getting a 404 with {*aString}. Also tried {*aString*}. No diff. On a lesser note, this does not explain why the error does not occur when using visual studio debugger. – P.Brian.Mackey Mar 21 '11 at 17:13
  • Just tested it here and it works fine. `{*aString*}` won't work it has to be `{*aString}`. I am running IIS7 so it could be an issue with that? Are you running IIS6? – Buildstarted Mar 21 '11 at 18:10
  • With regards to the debugger. It could be dependent on what version of IIS you're publishing to. – Buildstarted Mar 21 '11 at 18:11
  • @BuildStarted - Perhaps so: IIS6 – P.Brian.Mackey Mar 21 '11 at 18:20
  • @BuildStarted - That would help explain why it works fine in my visual studio debugger, but blows up in IIS...if its the version of IIS that can't handle the routing properly. – P.Brian.Mackey Mar 21 '11 at 18:51
  • Yeah, I checked it on IIS 6 and it doesn't work there either. Depending on where your content is located you could possibly call `routes.RouteExistingFiles = false;` - that will make MVC handle all requests or you can http://professionalaspnet.com/archive/2007/07/27/Configure-IIS-for-Wildcard-Extensions-in-ASP.NET.aspx try this. Again, I'm not sure what the results will be using either of these methods. – Buildstarted Mar 21 '11 at 19:13