无法使用 ip:port 访问 WEB API,但可以在 VS 调试模式下使用 localhost:port

Can#39;t access WEB API with ip:port but can with localhost:port during VS debug mode(无法使用 ip:port 访问 WEB API,但可以在 VS 调试模式下使用 localhost:port)
本文介绍了无法使用 ip:port 访问 WEB API,但可以在 VS 调试模式下使用 localhost:port的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am trying to write an WEB API from .net and trying for my Android Application to query some data from the sql server database.

I have the web api written and it works well in debug mode.

My question is I notice the url of that application is localhost:port and it runs fine. However, when I try to change it to MYIP:port (eg. http:192.168.X.1234) or MYHOSTNAME:port (eg win7home:1234) this gives me Bad Request - Invalid Hostname.

I know I can deploy this to IIS and my IIS is setup but I was just wondering how come it doesn't work in debug mode???

Is there a way for me to run it in debug mode and test in on my Android at the same time instead of having to deploy it every time I want to make a change?

解决方案

Both Anton and Matthew's Answers pointed me to the right direction

So this what I did

  1. Run Visual Studios in administrator mode

  2. Changed the binding protocols and allow for incoming directions as suggested http://johan.driessen.se/posts/Accessing-an-IIS-Express-site-from-a-remote-computer

    But after that, I have a service unavailable (503) error

  3. So I followed this : IIS Express Enable External Request - 503 Added just the port protocol and port:ip protocol,

Than it works both on my machine's browser and on my phone.

Not too too sure why the 3rd step is needed -my hypothesis is (the localhost url is needed for VS to point to and the ip url is used for accessing from another machine)

这篇关于无法使用 ip:port 访问 WEB API,但可以在 VS 调试模式下使用 localhost:port的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)