1.新建一个  webapiconfig.cs

    

   public static void register(httpconfiguration config)
    {
        // web api 配置和服务

        // web api 路由
        config.maphttpattributeroutes();

        config.routes.maphttproute(
            name: "watermeterinfo",
            routetemplate: "api/{controller}/{action}/{id}", //注意这里 action  不加上会出现找不到 cotrol的错误
            defaults: new { id = routeparameter.optional }
        );
    }

 

2.没有global.asax.cs文件的添加 一个名称是这个的类 继承 system.web.httpapplication  也可以右键添加类 所有全局类

3.  global.asax.cs 开始 添加 webapiconfig 注册