amazon web services - Unable to Access Owin Self hosted RestApi - Deployed to AWS EC2 - Windows 2012 R2 -
following sample self hosting restapi code, have created owin. working in local machine.
i have hosted in aws-ec2, , started administrator.
i able access restapi inside instance (using chrome/ie) giving localhost url.
but getting bad request invalid hostname, when replace localhost public dns of instance (running within instance's browser).
when tried access restapi outside instance browser local machine (browser/postman), returning status 0.
copied code below.
class program { static void main(string[] args) { const string baseuri = "http://localhost:65435"; console.writeline("starting web server..."); webapp.start<startup>(baseuri); ... } } public class startup { public void configuration(iappbuilder app) { var webapiconfiguration = configurewebapi(); app.usewebapi(webapiconfiguration); } private httpconfiguration configurewebapi() { var config = new httpconfiguration(); config.routes.maphttproute( "defaultapi", "api/{controller}/{id}", new { id = routeparameter.optional }); return config; } } public class companiescontroller : apicontroller { public ienumerable<company> get() { return new list<company>(){ new company() { id = 1, name = "microsoft" }, new company() { id = 2, name = "amazon" } }; } }
i have created windows 2012 r2 - aws ec2 instance.
configured instance:
- to allow traffic in inbound , outbound.
- opened ports.
- i have disabled windows firewall
- i have tried ping dns name local machine cmd, , success.
- webapi using, port number - 65435 (ephemeral port)
- owin version - 5.2.3.0, .net version - 4.5 (4.5.2 installed on ec2 instance)
- changed "localhost" in code public-dns (same issue persists) , ip-address (throws exception - "exception has been thrown target of invocation.")
please me configure this.!!
you're starting webapp
on localhost:
http://localhost:65435
it's started on loopback adapter , not on actual ethernet adapter you're trying access outside. need start server's ip.
Comments
Post a Comment