多个Blazor应用程序,相同的托管.从第一个应用重定向到第二个.Azure应用服务 [英] Multiple Blazor apps, same hosting. Redirecting from the first app to the second. Azure App service

查看:74
本文介绍了多个Blazor应用程序,相同的托管.从第一个应用重定向到第二个.Azure应用服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have asp.net core hosting app and two Blazor WASM apps. Similar like this demo. Problem appears when I try to navigate from one app to an another. It works on local, but published version on Azure App Service (Linux) has this issue.

第二个应用程序位于/SecondApp 下,第一个应用程序位于根目录下.(这是差异表单演示应用程序).

Second app is under /SecondApp, first app is under the root. (this is the difference form demo app).

配置:

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 的链接.当我单击它时,它属于第一个应用程序:对不起,此地址没有任何内容.刷新页面(Ctrl + F5)时,它会毫无问题地加载第二个应用程序.

In the first app I have a link to https://localhost:5001/SecondApp. When I click that it falls to first app with: Sorry, there's nothing at this address. When I refresh the page (Ctrl+F5) it loads second app without problem.

再说一次,我在本地没有这个问题,只有天蓝色了.但是我不知道有任何配置可能会影响到这一点.

Again, I don't have this issue on local, only on azure. But I am not aware of any configuration that could influence this.

有什么想法吗?

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

EDIT: Maybe this is useful (?). If I specify fallback page instead of a file:

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

它抛出:

InvalidOperationException:找不到由路由值指定的回退端点:{页面:/a/Index,区域:}.

InvalidOperationException: Cannot find the fallback endpoint specified by route values: { page: /a/Index, area: }.

大编辑!

尝试了所有内容后,我关闭了Azure中的仅HTTPS 选项(在TLS/SSL设置下),并且可以正常工作.

After trying everything I turned off the HTTPS only option in Azure (under TLS/SSL settings) and it works.

我还创建了演示项目(

I also created demo project (github) with https on, so you can see the error.

推荐答案

哦,我3天尝试一切...

Oh my 3 days of trying everything...

渔获物在这一行:

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

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

This is fallback for naked app... When navigating from naked to second app it falls to index, it does not map to /secondapp... So the solution was specify fallback only for empty page:

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

这篇关于多个Blazor应用程序,相同的托管.从第一个应用重定向到第二个.Azure应用服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆