本文整理汇总了C#中System.Web.Http.SelfHost.HttpSelfHostConfiguration.EnsureInitialized方法的典型用法代码示例。如果您正苦于以下问题:C# HttpSelfHostConfiguration.EnsureInitialized方法的具体用法?C# HttpSelfHostConfiguration.EnsureInitialized怎么用?C# HttpSelfHostConfiguration.EnsureInitialized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.SelfHost.HttpSelfHostConfiguration
的用法示例。
在下文中一共展示了HttpSelfHostConfiguration.EnsureInitialized方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var baseAddress = "http://localhost:8080";
HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(baseAddress);
// config.MessageHandlers.Add(new ProgressMessageHandler() { });
// Web API 路由
config.MapHttpAttributeRoutes();
//全局允许CROS
// config.EnableCors();//启用跨域
config.Routes.MapHttpRoute
(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.MaxConcurrentRequests = 1000;
var handlers = new DelegatingHandler[] { new PassiveAuthenticationMessageHandler(), new HttpServer() };
var routeHandlers = HttpClientFactory.CreatePipeline(new HttpControllerDispatcher(config), handlers);
config.Routes.MapHttpRoute(
name: "CustomerRouter",
routeTemplate: "MyAPI/{Controller}/{Action}/Id",
defaults: new { Id = RouteParameter.Optional },
constraints: null,
handler: routeHandlers
);
HttpSelfHostServer server = new HttpSelfHostServer(config);
server.OpenAsync();
TaskManager.Instance.Initialize();
TaskManager.Instance.Start();
DefaultHttpBatchHandler batchHandler = new DefaultHttpBatchHandler(server);
Console.WriteLine("Server http://localhost:8080 Open now ....at {0}..", server.Configuration.VirtualPathRoot);
config.EnsureInitialized();
foreach (var route in config.Routes)
{
System.Diagnostics.Debug.WriteLine(route);
}
Console.ReadLine();
}
示例2: OnStart
protected override void OnStart(string[] args)
{
Uri baseAddress = new Uri("http://" + ConfigurationManager.AppSettings["server"] + GetPort());
HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(baseAddress)
{
HostNameComparisonMode = HostNameComparisonMode.Exact
};
string origins = ConfigurationManager.AppSettings["corsItems"];
if (string.IsNullOrEmpty(origins))
{
origins = "*";
}
config.EnableCors(new EnableCorsAttribute(origins, "*", "*"));
var formatters = GlobalConfiguration.Configuration.Formatters;
formatters.Remove(formatters.XmlFormatter);
WebApiConfig.Register(config);
config.MapHttpAttributeRoutes();
config.EnsureInitialized();
_server = new HttpSelfHostServer(config);
// Start listening
_server.OpenAsync().Wait();
System.Console.WriteLine("Listening on " + baseAddress);
}