Does ASP.NET MVC have DateTime route restrictions?

Does ASP.NET MVC contain any route contraindications baked in code? if so, how to determine the time limit?

eg. URL:

http://mydomain.com/{versionDate}/{controller}/{action}
http://mydomain.com/2010-01-20/search/posts

cheers :)

+5
source share
3 answers

I ended up doing my own route. took only a few minutes.

using System;
using System.Web;
using System.Web.Routing;

namespace Whatever.Your.Funky.Cold.Medina.Namespace.Is
{
    public class DateTimeRouteConstraint : IRouteConstraint
    {
        #region IRouteConstraint Members

        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values,
                          RouteDirection routeDirection)
        {
            DateTime dateTime;

            return DateTime.TryParse(values[parameterName] as string, out dateTime);
        }

        #endregion
    }
}

simple: P

+10
source

You can also set a route restriction, something like this. The regular expression used is not very reliable, so you should clarify it.

routes.MapRoute( 
    "Version", "
    {versionDate}/{controller}/{action}", 
    new {controller="Search", action="Posts"}, 
    new {versionDate= @"\d\d\d\d-\d\d-\d\d" } 
    ); 

Information from here .

+2
source

, , , , @jrista , else mvc // 2010-01-20

0
source

All Articles