惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
D
Docker
Vercel News
Vercel News
IT之家
IT之家
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
腾讯CDC
Google DeepMind News
Google DeepMind News
I
InfoQ
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - Franky
The Cloudflare Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
T
Tenable Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Security Latest
Security Latest
H
Hackread – Cybersecurity News, Data Breaches, AI and More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
F
Full Disclosure
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
Project Zero
Project Zero

博客园 - Aricc

如何在已有内网网络中增加项目专用域名解析服务器(DNS) Windows使用命令行查看cpu的温度 屌丝公司:设置服务器的时区、时间及时间同步 从QNAP威联通NAS的Container Station中的容器中复制文件到本地Window电脑 sourcetree外部差异/合并工具设置 树莓派插入U盘自动拷贝系统日志到U盘或通过U盘升级程序 树莓派开通VPN服务端时IPTable设置 - Aricc 动态调用WebService的代理类 如何一步一步新建一个Owin项目 WebApi Owin OAuth Sql Server查看死锁及堵塞脚本 路由表脚本 配电管家 数据绑定时(<%#Eval)单引号双引号嵌套问题 About SSDT BI 在Win8中用批处理创建Oracle数据库时报“Unable to open file” 收藏网址 SQL SERVER 2005 CLR存储过程调用WCF,64位操作系统。 TX-2B/RX-2B射频发送/接收电路
为Owin项目增加WebApi
Aricc · 2017-07-28 · via 博客园 - Aricc

上一篇文章我们新建了一个Owin项目。

本节,我们来为其增加WebApi功能

项目右键》添加》新搭建基架的项目

选择Web API 2控制器

为默认控制器命名

点击添加后项目结构如下:

将WebApiConfig.cs排除出项目(我们这里用的是Owin,WebApi模板默认的注册逻辑就没用了)

同理,Global.asax.cs中GlobalConfiguration.Configure(WebApiConfig.Register);也注释掉,或者删除。

打开DefaultController.cs,添加如下代码:

        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

向Startup类增加如下代码:

            var config = new HttpConfiguration();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional, action = RouteParameter.Optional }
                );
            app.UseWebApi(config);

注意,把之前的app.Run测试代码注释掉

然后访问http://localhost:33964/api/default

已经可以正常访问了。IE弹出下载提示框。

使用FF上的Rest调试工具访问:

好了,目前已经可以正常访问WebApi里的相应控制器方法了。