【ASP.NET】System.Web.Routing - HttpMethodConstraint Class

你可以自己定义你的ASP.NET程序接收的get post put 或者delete请求。

使用这个约束的方式为:

void Application_Start(object sender, EventArgs e) 
{
    RegisterRoutes(RouteTable.Routes);
}

public static void RegisterRoutes(RouteCollection routes)
{
    string[] allowedMethods = { "GET", "POST" };
    HttpMethodConstraint methodConstraints = new HttpMethodConstraint(allowedMethods);

    Route reportRoute = new Route("{locale}/{year}", new ReportRouteHandler());
    reportRoute.Constraints = new RouteValueDictionary { { "httpMethod", methodConstraints } };

    routes.Add(reportRoute);
}

 参考资料: https://docs.microsoft.com/en-us/dotnet/api/system.web.routing.httpmethodconstraint?view=netframework-4.7.2

posted @ 2018-11-06 14:19  YanyuWu  阅读(152)  评论(0编辑  收藏  举报