Reputation: 9387
Want to host 2 asp .net core 2 websites in Azure service fabric which use port 80. In this link they mentions port sharing but not sure how to configure this? is there a way to mention host name?
Upvotes: 2
Views: 1303
Reputation: 11
If this is a .NET CORE stateless WEB Service API then use HttpSys. However, HttpsSys can be only used with IIS and not KESTREL.
To use HttpSys in a stateless service, override the CreateServiceInstanceListeners method and return a HttpSysCommunicationListener instance: C#
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new ServiceInstanceListener[]
{
new ServiceInstanceListener(serviceContext =>
new HttpSysCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
new WebHostBuilder()
.UseHttpSys()
.ConfigureServices(
services => services
.AddSingleton<StatelessServiceContext>(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseStartup<Startup>()
.UseUrls(url)
.Build()))
};
}
also change url to something different than the default:
.UseUrls(url+="WebService")
so for a localhost on port 80 the URL would be:
http(s)//localhost.com/WebService/api/foo
Upvotes: 1
Reputation: 81
Use this class:
public class HttpSysInstanceListener
{
public static ServiceInstanceListener[] CreateListener(Type startupType, string endpointName, string rootPath, int port)
{
return new ServiceInstanceListener[]
{
new ServiceInstanceListener(serviceContext =>
new HttpSysCommunicationListener(serviceContext, $"{endpointName}", (url, listener) =>
{
return new WebHostBuilder()
.UseHttpSys(options =>
{
options.UrlPrefixes.Add($"http://+:{port}/{rootPath}/");
options.Authentication.Schemes = Microsoft.AspNetCore.Server.HttpSys.AuthenticationSchemes.None;
options.Authentication.AllowAnonymous = true;
options.MaxConnections = null;
})
.ConfigureServices(services => services
.AddSingleton<StatelessServiceContext>(serviceContext)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup(startupType)
.UseUrls(url)
.UseApplicationInsights()
.Build();
}))
};
}
}
Upvotes: 1