【发布时间】: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