.Net WEBAPI创建

时间:2020-07-08 13:13:27   收藏:0   阅读:77

在mvc的解决方案中,增加webapi接口。

新添加Controller,模板选用webapi,由于原来mvc版本使用4.5,所以webapi也使用4.5,创建完成后,会在app_start中创建webapiconfig的配置文件。

技术图片

 

 ps:自动创建的无action,需要添加action。

添加完后,在global.asax文件application_strat中添加

GlobalConfiguration.Configure(WebApiConfig.Register);(此必须在最前面)

在Controllers中

[RoutePrefix("api/WebApi")]
public class WebApiController : ApiController
{ 

[HttpGet]
[Route("Get)]
public string Get()

{return "hello";}

}

运行即可,访问localhost:xxxx/api/webapi/get

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!