[英]Unable to Access Owin Self hosted RestApi - Deployed to AWS EC2 - Windows 2012 R2
Following is the sample self hosting Rest API code, I have created with OWIN.以下是我使用 OWIN 创建的示例自托管 Rest API 代码。 It is working in my local machine.
它在我的本地机器上工作。
i have hosted it in aws-ec2, and started as administrator.我将它托管在 aws-ec2 中,并以管理员身份启动。
I am able to access the Rest API from inside the instance (using chrome/IE) giving localhost as URL.我能够从实例内部(使用 chrome/IE)访问 Rest API,将本地主机设为 URL。
But getting a Bad request invalid hostname, when i replace the localhost with public DNS of Instance (running within Instance's browser).但是,当我将本地主机替换为实例的公共 DNS(在实例的浏览器中运行)时,收到错误的请求无效主机名。
when i tried to access the RestApi from outside the instance browser from my local machine (browser/postman), it is returning status 0.当我尝试从本地计算机(浏览器/邮递员)的实例浏览器外部访问 RestApi 时,它返回状态 0。
Copied the 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 a Windows Server 2012 R2 - AWS EC2 instance.我创建了一个 Windows Server 2012 R2 - AWS EC2 实例。
Configured the instance:配置实例:
Please help me to configure this.请帮我配置一下。
You're starting the WebApp
on localhost: 您正在localhost上启动
WebApp
:
http://localhost:65435
It's started on the loopback adapter and not on the actual ethernet adapter that you're trying to access from outside. 它是在环回适配器上启动的,而不是在您尝试从外部访问的实际以太网适配器上启动的。 You need to start it with the server's ip.
你需要用服务器的ip启动它。
If nobody can solve this problem, then OWIN is useless to me. 如果没有人能解决这个问题,那么OWIN对我来说毫无用处。 "Switching back to IIS"
“切换回IIS”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.