mvc webapi路由重写
来源:互联网 发布:破解软件网盘 编辑:程序博客网 时间:2024/05/23 23:53
修改app_start/webapiconfig.cs
using System.Web.Http;using System.Web.Routing;using Ninject;using TxMobile.Filters;using TxMobile.Models;using WebApiContrib.IoC.Ninject;namespace TxMobile{ /// <summary> /// WebApi路由配置 /// </summary> public static class WebApiConfig { /// <summary> /// 构造函数 /// </summary> /// <param name="config"></param> public static void Register(HttpConfiguration config) { config.Filters.Add(new ValidateAttribute()); IKernel kernel = new StandardKernel(); kernel.Bind<ICommentRepository>().ToConstant(new InitialData()); config.DependencyResolver = new NinjectResolver(kernel); config.Routes.MapHttpRoute( name: "productlist", routeTemplate: "{controller}/prod/list", defaults: new { controller = "IAP", action = "ProductList" }, constraints: new { httpMethod = new HttpMethodConstraint("GET","Post") } ); config.Routes.MapHttpRoute( name: "productbuy", routeTemplate: "{controller}/prod/buy", defaults: new { controller = "IAP", action = "ProductBuy" }, constraints: new { httpMethod = new HttpMethodConstraint("GET","Post") } ); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); } }}
注意事项:
1、可以对某个action进行重写,写成任意格式的url
2、必须要把重写的action路由代码,放到DefaultApi前面。
0 0
- mvc webapi路由重写
- MVC WebApi 路由设置(自定义) 分区Area
- 给ASP.NET MVC及WebApi添加路由优先级
- 在ASP.NET MVC中使用WebApi注册路由注意事项
- ASP.NET Core MVC-WebAPi如何构建路由?
- ASP.NET Core MVC-WebAPi如何构建路由?
- ASP.NET Core MVC-WebAPi如何构建路由?
- ASP.NET Core MVC-WebAPi如何构建路由?
- MVC WEBAPI
- WebAPI路由、参数绑定
- MVC自定义路由实现URL重写,SEO优化
- MVC中的webApi
- WebApi&MVC对比
- WebApi设置namespace路由参数
- 【开源】NodeJS仿WebApi路由
- 【开源】NodeJS仿WebApi路由
- 【开源】NodeJS仿WebApi路由
- 【开源】NodeJS仿WebApi路由
- Problem A: STL——邮票
- Java线程Dump分析工具
- 分解质因数
- UOJ 109 [APIO2013]TASKSAUTHOR
- Github搜索技巧-如何使用github找到自己感兴趣的项目
- mvc webapi路由重写
- OpenGL学习笔记(二)
- ZOJ3878 onvert QWERTY to Dvorak
- Linux下隐藏文件和显示隐藏文件命令
- 4412驱动-按键 蜂鸣器 流水灯
- HTTP 代理和反向代理
- windows DLL编程基础
- 在HTML中,如何设置新窗口打开和在原窗口打开? herf的属性
- js 异步和事件的执行问题