在Azure服务结构中的ASP.NET核心中使用WebListener
问题描述:
我想在Azure服务结构中的ASP.NET核心应用程序中使用WebListener。在Azure服务结构中的ASP.NET核心中使用WebListener
我已经做了以下内容:
Task<string> ICommunicationListener.OpenAsync(CancellationToken cancellationToken)
{
var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(_endpointName);
string serverUrl = $"{endpoint.Protocol}://{FabricRuntime.GetNodeContext().IPAddressOrFQDN}:{endpoint.Port}";
_webHost = new WebHostBuilder().UseWebListener()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseUrls(serverUrl)
.Build();
_webHost.Start();
return Task.FromResult(serverUrl);
}
可惜的是,这并不工作。我创建了一个Web API控制器,当我把这个返回404
当我使用红隼它的工作原理:
_webHost = new WebHostBuilder().UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseUrls(serverUrl)
.Build();
这是我projects.json:
{
"dependencies": {
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Routing": "1.0.1",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.AspNetCore.Server.WebListener": "1.1.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.ServiceFabric": "5.3.301",
"Microsoft.ServiceFabric.Data": "2.3.301",
"Microsoft.ServiceFabric.Services": "2.3.301"
},
"commands": {
"weblistener": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener"
},
"tools": {
},
"frameworks": {
"net452": {
"dependencies": {
}
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"**/*.cshtml",
"appsettings.json",
"web.config"
]
},
"scripts": {
}
}
我错过什么? 使用Web Listener的原因是我想将Windows身份验证与我的Intranet应用程序一起使用,以便用户不必手动输入用户名和密码。
答
尝试使用通配符的主机,像这样:
string serverUrl = $"{endpoint.Protocol}://+:{endpoint.Port}";