I'm using aws Windows Server 2022 Datacenter build 21H2. trying to host owin with webapi.
My pc os is windows 10
.net framework 4.8
webapi only reachable from localhost:port/endpoint. Not able to access in local machine with machinename:port/endpoint.
I have public IP, with public IP also not able to access in local mahcine and outside network also. complete firewall off, I test same port with sample tomcat application, and simple flask application both java-tomcat server and flask application reachable from outside network.
But .net owin self hosted can't be reachable on same port or different port from outside network(i close all other web servers before using same port). So this is not firewall or port issue and not I believe not related aws internal vps firewall, because simple flask server is able access from public ip.
before I post this question spent good amount of time (almost two weeks) in fixing this problem and seen almost all answers around it, but could not resolve it. answer 1, answer
complete code to replicate the error
public class WebServerStartup
{
public void Configuration(IAppBuilder appBuilder)
{
HttpConfiguration config = new HttpConfiguration();
appBuilder.UseCors(CorsOptions.AllowAll);
config.MapHttpAttributeRoutes(); //Don't miss this
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
((Newtonsoft.Json.Serialization.DefaultContractResolver)config.Formatters.JsonFormatter.SerializerSettings.ContractResolver).IgnoreSerializableAttribute = true;
appBuilder.UseWebApi(config);
}
}
Just an example to host on click
private void ButtonHost_OnClick(object sender, RoutedEventArgs e)
{
try
{
// CASE 1 Tried
StartOptions options = new StartOptions();
options.Urls.Add($"http://localhost:{txtProt.Text.Trim()}");
options.Urls.Add($"http://127.0.0.1:{txtProt.Text.Trim()}");
options.Urls.Add($"http://{Environment.MachineName}:{txtProt.Text.Trim()}" );
WebApp.Start<WebServerStartup>(options: options);
}
catch (Exception exception)
{
TextBlockStatus.Text = JsonConvert.SerializeObject(exception);
}
}
from admin command prompt added netsh http add urlacl url=http://AMAZ-V5775TY37B:9989/ user=Administrator
localhost:port
machinename:port
this is working fine in my localmachine.
//CASE 2 without StartOptions tried with # working in local and aws, but not public ip
WebApp.Start<Startup>("http://*:8080");
//CASE 3 # working in local and aws
WebApp.Start<Startup>("http://localhost:8080");
//CASE 4 # working in localpc but not in aws
WebApp.Start<Startup>("http://localip:8080"); // 192.168.1.x
in any case it is not working with public ip, but same pubic ip with same port working for flask and tomcat without any additional configuration.
do i miss any configuration in own config, i tried to run application as administrator, still same error;
ERROR: connection refused