In .NET 4.5 / WebApi 2, i could create a constraint and add it using this code
// add constraint resolvers
var constraintResolver = new DefaultInlineConstraintResolver();
constraintResolver.ConstraintMap.Add("constraintName", typeof(MyCustomConstraint));
// routing
config.MapHttpAttributeRoutes(constraintResolver);
Currently in my Startup.cs file, i just have this
public void Configure(IApplicationBuilder app, IServiceProvider serviceProvider)
{
// Enable Mvc for controllers
app.UseMvc();
// Enable all static file middleware (serving of static files and default files) EXCEPT directory browsing.
app.UseFileServer();
}
But i cannot figure out where to do this i asp.net 5/vNext. Can someone please help? I am using attribute routing on all my controllers
You can register in the ConfigureServices section of the Startup class.
public virtual IServiceProvider ConfigureServices(IServiceCollection services)
{
services.Configure<RouteOptions>(options =>
options
.ConstraintMap
.Add("constraintName", typeof(MyCustomConstraint)));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.