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
开发者_StackOverflow中文版 "{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);
}
}
}
Verify that the page is accessible:
http://serverName/QueryStuff/Index/someInfo
You should get http 200.
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.
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.
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
);
精彩评论