游戏技术文章

mvc webapi路由重写

时间:2017-5-1 12:46:28  作者:棋牌资源网  来源:棋牌资源网  查看:8910  评论:0
内容摘要:修改app_start/webapiconfig.csusing System.Web.Http;using System.Web.Routing;using Ninject;using TxMobile.Filters;using TxMobile.Models;using W...
修改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前面。

标签:mvcwebapi路由重写 

欢迎加入VIP,【VIP售价:只要288元永久VIP会员】畅享商业棋牌游戏程序下载,点击开通!

下载说明


☉本站所有源码和资源均由站长亲自测试-绝对保证都可以架设,运营!
☉如源码和资源有损坏或所有链接均不能下载,请告知管理员,

☉本站软件和源码大部分为站长独资,资源购买和收集,放心下载!

☉唯一站长QQ:1004003180  [人格担保-本站注重诚信!]

☉购买建议E-mail:1004003180@qq.com   源码收购 E-mail:1004003180@qq.com    

☉本站文件解压密码  【文章内都自带解压密码,每个密码不同!】


本站提供的所有源码,均来源站长提供,仅学习交流 浙ICP备09009969号

由此产生不良后果和法律责任与本站无关,如果侵犯了您的版权,请来信告知 1004003180@qq.com 将及时更正和删除! 

Copyright © 2008-2021 棋牌资源网,你身边的棋牌资源下载站    All Rights Reserved