Manifest 未从 .NET Core Web 应用程序正确加载

问题描述 投票:0回答:0

只是为了从技术角度尝试看看有什么可能,我正在尝试将带有 Razor Pages(NO MVC!)的 .NET Core Web 应用程序制作成渐进式 Web 应用程序(PWA),但我遇到了问题在这里。

我的浏览器不想加载我正确创建的清单。在 Chrome DevTools 中,我收到这条消息,指出第 1 行第 1 列存在语法错误,但是当我单击指向 webmanifest 的链接时,它显示“未找到具有给定 URL 的资源”。这让我得出结论,它只是拒绝加载我的清单。

我遵循了一个教程(他们使用的是 MVC 网络应用程序,我没有)并安装了 NuGet 包“WebEssentials.AspNetCore.PWA”并将以下行添加到我的 Program.cs 文件中:

builder.Services.AddProgressiveWebApp();

这使得它看起来像这样:

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapRazorPages();

app.Run();

然后我在 wwwroot 文件夹中创建了一个 manifest.json 文件,内容如下:

{
    "name": "Razor PWA",
    "short_name": "Razor PWA",
    "icons": [
        {
            "sizes": "192x192",
            "type": "image/png",
            "src": "/img/icon-192.png"
        },
        {
            "sizes": "512x512",
            "type": "image/png",
            "src": "/img/icon-512.png"
        }
    ],

    "display": "minimal-ui",
    "theme_color": "#2dab66",
    "orientation": "portrait",
    "background_color": "#2dab66",
    "start_url": "/"
}

我还将图标添加到与 manifest.json 相同位置的 img 文件夹中。

我还在 MVC 项目中尝试了完全相同的过程,效果非常好。所以我确信 MVC 和非 MVC 之间存在差异,这会阻止相同的进程工作,我想知道是否有任何配置需要更改,或者甚至不可能进行非 -使用此包将 MVC 应用程序转换为 PWA?

我会很高兴得到任何答案!

c# .net-core progressive-web-apps razor-pages web-essentials
© www.soinside.com 2019 - 2024. All rights reserved.