给现有MVC项目增加Web API支持
在MVC4中自带了Web API不再需要从Nuget中下载。
Step1:增加System.Web.Http,System.Web.Http.WebHost,System.Net.Http三个程序集的引用,都是4.0版本;
Step2:增加路由,默认的路由代码如下
routes.MapHttpRoute(
name: "API Default",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Step3:新增一个MyController,父类为ApiController,你可能需要增加System.Web.Http命名空间;
Step4:写几个Method,比如 public IEnumerable<string> GetAllChannels();
Step5:大功告成,在浏览器中输入http://xxxx/api/My/ 如果在地址最后没有跟上method名它会默认查找第一个包含“Get”关键字的方法,这里会返回GetAllChannels的结果。
给现有MVC项目增加Web API支持的更多相关文章
- 如何将一个 ASP.NET MVC 4 和 Web API 项目升级到 ASP.NET MVC 5 和 Web API 2
----转自微软官网www.asp.net/mvc/ ASP.NET MVC 5 和 Web API 2 带来的新功能,包括属性路由. 身份验证筛选器,以及更多的主机.请参阅http://www.as ...
- 002.Create a web API with ASP.NET Core MVC and Visual Studio for Windows -- 【在windows上用vs与asp.net core mvc 创建一个 web api 程序】
Create a web API with ASP.NET Core MVC and Visual Studio for Windows 在windows上用vs与asp.net core mvc 创 ...
- 通过扩展让ASP.NET Web API支持JSONP
同源策略(Same Origin Policy)的存在导致了"源"自A的脚本只能操作"同源"页面的DOM,"跨源"操作来源于B的页面将会被拒 ...
- 通过扩展让ASP.NET Web API支持W3C的CORS规范
让ASP.NET Web API支持JSONP和W3C的CORS规范是解决"跨域资源共享"的两种途径,在<通过扩展让ASP.NET Web API支持JSONP>中我们 ...
- 通过扩展让ASP.NET Web API支持W3C的CORS规范(转载)
转载地址:http://www.cnblogs.com/artech/p/cors-4-asp-net-web-api-04.html CORS(Cross-Origin Resource Shari ...
- MVC中使用Web API和EntityFramework
在ASP.NET MVC中使用Web API和EntityFramework构建应用程序 最近做了一个项目技术预研:在ASP.NET MVC框架中使用Web API和EntityFramework ...
- (转)通过扩展让ASP.NET Web API支持JSONP
原文地址:http://www.cnblogs.com/artech/p/3460544.html 同源策略(Same Origin Policy)的存在导致了“源”自A的脚本只能操作“同源”页面的D ...
- 让Web API支持Protocol Buffers
简介 现在我们Web API项目基本上都是使用的Json作为通信的格式,随着移动互联网的兴起,Web API不仅其他系统可以使用,手机端也可以使用,但是手机端也有相对特殊的地方,网络通信除了wifi, ...
- 通过微软的cors类库,让ASP.NET Web API 支持 CORS
前言:因为公司项目需要搭建一个Web API 的后端,用来传输一些数据以及文件,之前有听过Web API的相关说明,但是真正实现的时候,感觉还是需要挺多知识的,正好今天有空,整理一下这周关于解决COR ...
随机推荐
- 排序基础之插入排序、冒泡排序、选择排序详解与Java代码实现
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6594533.html 一:插入排序==逐个往前相邻数比较交换,小的在前 第一轮:A[1]与A[0]比较,小的 ...
- Plus One 加一运算
Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...
- climbing-stairs-动态规划,爬楼梯的路径数
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- unique_ptr与std::move的使用
形参为unique_ptr u2,而后实参为std::move(unique_ptr u1),这样会将原本u1的内存传递给u2,避免了传递拷贝.例如: void fun(std::unique_ptr ...
- POJ 3268 Bookshelf 2 动态规划法题解
Description Farmer John recently bought another bookshelf for the cow library, but the shelf is gett ...
- weblogic启动报错|unable to create new native threadjava
问题描述: <-- 上午10时20分01秒 CST> <Critical> <WebLogicServer> <BEA-> <Server sub ...
- PendingIntent传递数据注意参数RequestCode和Flag
数据发送方: public static void notify(Context context, TxrjMessage msg) { NotificationManager notifiM ...
- ios中webview的高级用法
.隐藏上下滚动时出边界的后面的黑色的阴影 - (void) hideGradientBackground:(UIView*)theView { for (UIView * subview in the ...
- iOS中coreData的用法
// // ViewController.m // coredatademo002 // // Created by ganchaobo on 13-6-29. // Copyright (c) 20 ...
- tableview中头部信息
//创建tableview中头部的文件#define kPadding 10 #define kIconWidth 100 #define kIconHeight 100 #define kCount ...