正文
【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