Routing with a Guid in ASP.NET MVC
I have a url which will take the following form:
/AuditReview/Review/15d49a66-5c11-492c-921f-9e1700bd2618
开发者_JS百科
I cannot get this to route, my routes look like this:
MvcRoute.MappUrl("{controller}.mvc.aspx/{action}/{auditEventUid}")
.WithDefaults(new {controller = "AuditReview", action = "Review"})
.WithConstraints(new { controller = "AuditReview", action ="Review", auditEventUid = new GuidConstraint() });
MvcRoute.MappUrl("admin/{controller}.mvc.aspx/{action}")
.WithDefaults(new { controller = "audit", action = "index" })
.WithConstraints(new{controller = "audit"})
.AddWithName("admin", routes);
MvcRoute.MappUrl("{controller}.mvc.aspx/{action}")
.WithDefaults(new {action = "Index"})
.AddWithName("Default", routes);
Can anyone suggest a route to make this work?
Your current routing rules would require you to access the url using:
/AuditReview.mvc.aspx/Review/15d49a66-5c11-492c-921f-9e1700bd2618
If you're running IIS 7 or have enough access to the server to install wildcard mapping you can just remove the .mvc.aspx
from your routing rules and your original url will work.
This should work - I am able to map a simpler scenario fine. Can you get this scenario to work with a simpler route (e.g. the default "{controller}.mvc/{action}/{id}" route)?
Have you tried removing the GuidConstraint or testing to make sure that the GuidConstraint works? Perhaps that is not working properly.
精彩评论