System.Web.Routing - HttpMethodConstraint Class
阿新 • • 發佈:2018-11-06
你可以自己定義你的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); }