i create attribute routing in mvc 5 application 1 simple constraint:
public class useragentconstraint : irouteconstraint { private string _requireduseragent; public useragentconstraint(string requireduseragent) { _requireduseragent = requireduseragent; } public bool match(httpcontextbase httpcontext, route route, string parametername, routevaluedictionary values, routedirection routedirection) { return httpcontext.request.useragent != null && httpcontext.request.useragent.contains(_requireduseragent); } } in mvc 4 able register in way:
routes.maproute("chromeroute", "{*catchall}", new { controller = "home", action = "index" }, new { customconstraint = new useragentconstraint("chrome") }); how can achieve same result using only attribute routing? know can register constraint in way:
var constraintsresolver = new defaultinlineconstraintresolver(); constraintsresolver.constraintmap.add("useragent", typeof(useragentconstraint)); but how add route pattern? this:
[route("home/index:useragent(chrome)")] public actionresult index() {} doesnt work
review aspnetmvc source code,it can helpful , try review
routecontraintattribute , areaattribute , routeattribute
for example routeconstraintattribute:
https://github.com/aspnet/mvc/blob/dev/src/microsoft.aspnet.mvc.core/routeconstraintattribute.cs
i'm trying figure out how that.
Comments
Post a Comment