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 的时候,使用管理员权限启动