【问题标题】:Running ASP.NET Boilerplate template under virtual directory在虚拟目录下运行 ASP.NET Boilerplate 模板
【发布时间】:2019-04-10 15:22:03
【问题描述】:

我有一个由 ASP.NET Boilerplate 创建的 Angular 模板。我已经成功发布了它,它在一个网站下的 IIS 上运行顺利。但是,我的客户希望让它在虚拟目录下运行,而不是在自己的网站下运行。

我已将 appconfig.json 更新如下:

{
  "remoteServiceBaseUrl": "http://localhost:8080/Training",
  "appBaseUrl": "http://localhost:8080/Training"
}

并在 appSettings.json 中对 App 执行相同操作:

"App": {
    "ServerRootAddress": "http://localhost:8080/Training/",
    "ClientRootAddress": "http://localhost:8080/Training/",
    "CorsOrigins": "http://localhost:8080/Training"
}

由于某种原因,当我运行该应用程序时,我收到以下错误,它无法加载某些 CSS 和 JavaScript 包:

我手动更改了 wwwroot 文件夹中的 index.html 并将http://localhost:8080/Training/ 添加到每个 href 的开头。通过这样做,所有这些错误都消失了,现在我留下了这个错误:

GET http://localhost:8080/assets/appconfig.json 404 (Not Found)

我认为这与 AppPreBootstrap.ts 文件有关,它从 appconfig.json 文件中读取。

在发布应用程序之前,我是否必须在某处对应用程序设置进行任何更改才能消除上述问题?

【问题讨论】:

    标签: javascript iis aspnetboilerplate virtual-directory base-url


    【解决方案1】:

    确保 AppPreBootstrap.tsappRootUrl'/' 结尾:

    private static getApplicationConfig(appRootUrl: string, callback: () => void) {
        appRootUrl += appRootUrl.endsWith('/') ? '' : '/'; // Add this line
        return abp.ajax({
            url: appRootUrl + 'assets/' + environment.appConfig,
            // ...
        }).done(result => {
            // ...
        });
    }
    

    【讨论】:

    • 您的模板似乎是 v3.x。从提交 f20895b 复制更改,然后添加此答案中提到的行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-12
    相关资源
    最近更新 更多