WebAPI 使用控制台启动
2024-09-03 13:46:40
using System;
using System.Web.Http;
using System.Web.Http.SelfHost; namespace UAC_OAuth2Center
{
public class Program
{
static void Main(string[] args)
{
try
{
var config = new HttpSelfHostConfiguration("http://localhost:2021");
// Web API 配置和服务
config.EnableCors(new System.Web.Http.Cors.EnableCorsAttribute("*", "*", "*", "*"));
//config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional });
using (var sever = new HttpSelfHostServer(config))
{
sever.OpenAsync().Wait();
Console.WriteLine("SPC_Server服务已经成功启动!");
Console.WriteLine("输入任意字符关闭");
Console.Read();
sever.CloseAsync().Wait(); }
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadKey();
}
}
}
记住,启动VS 的时候,使用管理员权限启动
最新文章
- 版本控制-svn服务器搭建和常用命令(centos 6.3)
- Linux 基本命令
- 传入任意json数据源进行格式化处理并用Angularjs显示
- About_MySQL Select--来自copy_03
- (五)socket实践编程
- viewpager的简单使用,以及ValueAnimator的用法示例
- 未能加载文件或程序集“Enyim.Caching”或它的某一个依赖项。未能验证强名称签名
- 异常捕捉 ( try catch finally ) 你真的掌握了吗?
- IntellijIdea中常用的快捷键
- Contest20140710 eagleeggs
- ASP.NET页面周期
- mpls vpn剩余笔记
- 【转】Wi-Fi 20mhz 和 40mhz 频段带宽的区别是什么?
- jQuery(二)、选择器
- python之路(五)-文件操作
- PHP 弹窗 源代码 css Jquery.js
- jquery正则表达式验证:验证身份证号码
- 查询yum包安装路径
- linux系统编程之文件与IO(一):文件描述符、open,close
- UVA12538 Version Controlled IDE
热门文章
- WPF 中如何变相让 ListBox 宽度(Width) 100%,高度(Height) 100%,从而达到 Filled 的效果
- 【LOJ#3146】[APIO2019]路灯(树套树)
- mongodb复杂条件查询 (or与and)
- 高性能TcpServer(C#) - 2.创建高性能Socket服务器SocketAsyncEventArgs的实现(IOCP)
- CSS常用布局方式-两列布局、三列布局
- 在vue项目中通过iframe引入jquery项目
- 基于JQuery可拖动列表格插件DataTables的踩坑记
- android studio学习----常用快捷键
- vue学习指南:第四篇(详细) - vue的 :class 和 :style
- GCN