How to share a port with 2 services using WebListener in Asp.Net core.
I tried registering URL Prefixes as below,
netsh http add urlacl url=http://machinename:8080/Service1 user=xxx listen=yes
netsh http add urlacl url=http://machinename:8080/Service2 user=xxx listen=yes
But while starting the second service with same 8080 port, i am getting below error.
fail: Microsoft.Net.Http.Server.WebListener[0]
Start
Microsoft.Net.Http.Server.WebListenerException (0x80004005): The process cannot
access the file because it is being used by another process
at Microsoft.Net.Http.Server.UrlGroup.RegisterPrefix(String uriPrefix, Int32
contextId)
at Microsoft.Net.Http.Server.UrlPrefixCollection.RegisterAllPrefixes(UrlGroup
urlGroup)
at Microsoft.Net.Http.Server.WebListener.Start()
Here is the code
string baseAddress = "http://machinename:8080/Service1";
var builder = new WebHostBuilder()
.UseWebListener(options =>
{
options.ListenerSettings.Authentication.Schemes =
Microsoft.Net.Http.Server.AuthenticationSchemes.NTLM;
options.ListenerSettings.Authentication.AllowAnonymous = true;
})
.UseContentRoot(pathToContentRoot)
.UseStartup<Startup>()
.UseUrls(baseAddress);
host = builder.Build();
.UseHttpSys(options =>
{
options.UrlPrefixes.Add("http://localhost:5000");
options.Authentication.Schemes = AuthenticationSchemes.None;
options.Authentication.AllowAnonymous = true;
})
use this link: https://github.com/aspnet/HttpSysServer/blob/master/samples/SelfHostServer/Startup.cs
User contributions licensed under CC BY-SA 3.0