首页 > 解决方案 > 带有 .NET MVC 和 Angular 的动态服务器 baseUrl

问题描述

我正在用一个应用程序测试一些 SignalR,一切正常。现在要在服务器(azurewebsites)中对其进行测试,我需要将 baseUrl 设为动态并获取当前 url,以便可以建立 SignalR 集线器连接。

现在我有以下连接代码:

//server configuration
export let CONFIGURATION = {
    baseUrls: {
        server: 'http://localhost:51913'
    },
}

SomeMethod()
{
this.connection = $.hubConnection(CONFIGURATION.baseUrls.server);

//... the rest of the process to connect to the hub.
}

显然,这不适用于 localhost 作为 URL。如何获取主机 url 以开始我的连接?有什么方法可以获取它或从例如 WebConfig 中读取它?我只是不知道热它有效。

PS:也许有一些可能在没有特定网址的情况下连接到我的集线器?

标签: angularasp.net-mvcsignalr

解决方案


只是如果以后有人有同样的问题:

我会将静态地址放入环境中,它会相应地改变


推荐阅读