webapi与mvc的不同之处

关于webapi
1.以http协议传数据,可跨平台,跨终端
2.路由方面与mvc相同,分默认路由和特性路由
3.需要进行路由配置
4.通过ajax获得数据
5.mvc路由和webapi路由是分开的,webapi配置处WebApiConfig.cs,mvc路由配置处RouteConfig.cs
If you are familiar with ASP.NET MVC, Web API routing is very similar to MVC routing. The main difference is that Web API uses the HTTP method, not the URI path, to select the action. You can also use MVC-style routing in Web API. This article does not assume any knowledge of ASP.NET MVC.
6.返回形式不同
mvc返回的是ActionResult,是一个视图View
而webapi返回的是
1).void
2).HttpResponseMessage
3).IHttpActionResult
4).Some other type

详情:https://docs.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/action-results
7.寄宿形式不同:
ASP.NET Web API does not require IIS. You can self-host a web API in your own host process. This tutorial shows how to host a web API inside a console application.
8.调用方式不同,mvc通过浏览器输入地址字符串可访问,而webapi则需要通过AJAX调用webapi路由字符串(不一定是这样的。。。)
webapi默认是以get的方式请求的,如果要以post的方式请求,需要更改请求方式为post。
9.Self-Host Web API 和OWin-Host Web API是不同的,至少两个添加的NuGet包就不一样,前者是添加“Microsoft.AspNet.WebApi.SelfHost”后者是”Microsoft.AspNet.WebApi.OWinSelfHost”

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值