【问题标题】:Multiple Blazor apps, same hosting. Redirecting from the first app to the second. Azure App service多个 Blazor 应用程序,相同的托管。从第一个应用程序重定向到第二个应用程序。 Azure 应用服务
【发布时间】:2021-03-13 14:41:35
【问题描述】:

我有 asp.net 核心托管应用程序和两个 Blazor WASM 应用程序。类似于this demo。当我尝试从一个应用程序导航到另一个应用程序时出现问题。它适用于本地,但在 Azure App Service (Linux) 上发布的版本存在此问题。

第二个应用在/SecondApp 下,第一个应用在根目录下。 (这是差异形式演示应用程序)。

配置:

app.MapWhen(ctx => ctx.Request.Path.StartsWithSegments("/SecondApp",StringComparison.InvariantCultureIgnoreCase), second =>
{
    second.UseBlazorFrameworkFiles("/SecondApp");
    second.UseStaticFiles();
    second.UseStaticFiles("/SecondApp");
     
    second.UseRouting();

    second.UseIdentityServer();
    second.UseAuthentication();
    second.UseAuthorization();
    second.UseEndpoints(endpoints =>
    {
        endpoints.MapControllers();
        endpoints.MapRazorPages();
        endpoints.MapFallbackToFile("SecondApp/{**any}", "SecondApp/index.html");
    });
});

app.MapWhen(ctx => !ctx.Request.Path.StartsWithSegments("/SecondApp", StringComparison.InvariantCultureIgnoreCase), first =>
{
first.UseBlazorFrameworkFiles();
first.UseStaticFiles();
first.UseRouting();
first.UseIdentityServer();
first.UseAuthentication();
first.UseAuthorization();
first.UseEndpoints(endpoints =>
{
    endpoints.MapRazorPages();
    endpoints.MapControllers();
    //endpoints.MapFallbackToFile("index.html");
    //endpoints.MapFallbackToFile("{*path:regex(^(?!SecondApp).*$)}", "index.html"); 
    endpoints.MapFallbackToFile("{*path:nonfile}", "index.html");

});
});

在第一个应用程序中,我有一个指向 https://localhost:5001/SecondApp 的链接。当我点击它落入第一个应用程序时:Sorry, there's nothing at this address. 当我刷新页面 (Ctrl+F5) 时,它会毫无问题地加载第二个应用程序。

同样,我在本地没有这个问题,只有在 azure 上。但我不知道有任何配置会影响这一点。

有什么想法吗?

编辑: 也许这很有用(?)。如果我指定后备页面而不是文件:

 endpoints.MapFallbackToPage("a/{*path:nonfile}", "/a/Index");

它抛出:

InvalidOperationException:找不到路由值指定的回退端点:{ page: /a/Index, area: }。

大编辑!

在尝试了一切之后,我关闭了 Azure 中的 HTTPS only 选项(在 TLS/SSL 设置下),它可以正常工作。

我还创建了 demo project (github) 并启用了 https,因此您可以看到错误。

【问题讨论】:

  • 看看我写的一篇关于多 SPA 托管的文章 - codeproject.com/Articles/5287009/…。一会儿我看看你的配置,看看能不能看出问题
  • 作为上述评论的补充,它绝对适用于 Azure - cec-blazor-examples.azurewebsites.net。仔细检查所有 URL,特别是斜杠。我假设您在启动页面<base href="/red/" /> 中设置了StaticWebAssetBasePath 和基础。我也不在 URL 中使用大写字母,例如secondapp 而不是 SecondApp
  • 您的项目是我在这条通往多个 blazor 应用程序的路线上的灵感。非常感谢!我已经按照你的建议进行了一切设置。 (甚至是小写的变体)。我看到了我们的应用程序之间的一个区别。您的“索引”(根)应用程序是服务器之一。您所有的 wasm 应用程序都在 /something 下。但是我的根应用是wasm,和第二个一样...
  • 我取得了一些进展,请参阅大编辑。可能会转到另一个问题。
  • 稍后我将在我的测试站点上运行 WASM 作为根项目并发布我找到的答案。

标签: c# azure azure-web-app-service blazor blazor-webassembly


【解决方案1】:

哦,我尝试了所有的 3 天...

关键在这一行:

 endpoints.MapFallbackToFile("{*path:nonfile}", "index.html");

这是裸应用程序的后备...当从裸应用程序导航到第二个应用程序时,它会落入索引,它不会映射到/secondapp...所以解决方案只为空页面指定后备:

 endpoints.MapFallbackToFile("{*path:}", "index.html");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-16
    • 2019-04-03
    • 1970-01-01
    • 2015-12-28
    • 2012-12-02
    • 2020-03-29
    • 1970-01-01
    相关资源
    最近更新 更多