访问本地主机(Xamarin)
Accessing localhost(Xamarin)
我想使用 SignalR 在我的 android 应用程序中实现聊天,我从 asp.net 下载了这个示例:
https://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr
但我无法通过 HubConnection 使用本地主机访问它。我尝试使用我的 IP 地址和端口号,但它不起作用。有人有这方面的经验吗?
谢谢!
假设您的应用程序服务器是 IIS Express,由于网络限制甚至防火墙,它默认情况下无法运行。
首先,正如您已经意识到的那样,客户端需要连接到您的机器 ip,而不是本地主机。类似于 http://x.x.x.x:port/signalr
然后您需要确保您的机器可以从移动设备 phone 或模拟器访问:在 phone 中打开浏览器并输入一个已知地址,例如 http://x.x.x.x:port/somethingThatExists
。
如果 url 不可用:
- 尝试禁用防火墙
在机器上打开 powershell 运行ing IIS-Express 和 运行 这个:netsh http add urlacl url=http://{your server ip}:{port}/ user=everyone
。 (如果您的系统语言不是英语,例如:西班牙语,请将 "everyone" 更改为 "todos")
在目录解决方案 Solution/.vs/config/applicationhost.config
中打开文件 applicationhost.config
并搜索应用程序 xml 节点。类似于 <site name="YourAppName" id="1">...</site>
。默认情况下,您会看到 localhost
绑定。使用实际 ip 添加一个新的:<binding protocol="http" bindinginformation="*:port:x.x.x.x"></binding>
(确保 ip/port 正确。即:*:57457:192.168.0.57
)
重启IIS Express再试一次(无需重启系统)
我想使用 SignalR 在我的 android 应用程序中实现聊天,我从 asp.net 下载了这个示例: https://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr 但我无法通过 HubConnection 使用本地主机访问它。我尝试使用我的 IP 地址和端口号,但它不起作用。有人有这方面的经验吗?
谢谢!
假设您的应用程序服务器是 IIS Express,由于网络限制甚至防火墙,它默认情况下无法运行。
首先,正如您已经意识到的那样,客户端需要连接到您的机器 ip,而不是本地主机。类似于 http://x.x.x.x:port/signalr
然后您需要确保您的机器可以从移动设备 phone 或模拟器访问:在 phone 中打开浏览器并输入一个已知地址,例如 http://x.x.x.x:port/somethingThatExists
。
如果 url 不可用:
- 尝试禁用防火墙
在机器上打开 powershell 运行ing IIS-Express 和 运行 这个:
netsh http add urlacl url=http://{your server ip}:{port}/ user=everyone
。 (如果您的系统语言不是英语,例如:西班牙语,请将 "everyone" 更改为 "todos")在目录解决方案
Solution/.vs/config/applicationhost.config
中打开文件applicationhost.config
并搜索应用程序 xml 节点。类似于<site name="YourAppName" id="1">...</site>
。默认情况下,您会看到localhost
绑定。使用实际 ip 添加一个新的:<binding protocol="http" bindinginformation="*:port:x.x.x.x"></binding>
(确保 ip/port 正确。即:*:57457:192.168.0.57
)重启IIS Express再试一次(无需重启系统)