【问题标题】:Using WebListener in ASP.NET Core in Azure Service Fabric在 Azure Service Fabric 的 ASP.NET Core 中使用 WebListener
【发布时间】:2017-01-16 22:02:16
【问题描述】:

我想在 Azure Service Fabric 的 ASP.NET Core 应用程序中使用 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。

当我使用 Kestrel 时,它可以工作:

_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 的原因是我想在我的 Intranet 应用程序中使用 Windows 身份验证,这样用户就不必手动输入用户名和密码。

【问题讨论】:

    标签: azure-service-fabric asp.net-core-webapi weblistener


    【解决方案1】:

    尝试使用通配符主机,如下所示:

    string serverUrl = $"{endpoint.Protocol}://+:{endpoint.Port}";
    

    【讨论】:

      猜你喜欢
      • 2018-09-15
      • 2018-02-22
      • 2017-10-20
      • 2018-01-23
      • 2023-04-06
      • 2017-06-08
      • 2017-02-27
      • 2019-11-30
      • 2017-09-24
      相关资源
      最近更新 更多