我正在使用连接到 Firestore 数据库的 ASP.NET Core 托管模型(因此 3 个项目:客户端、服务器、共享)使用 Blazor WebAssembly 开发应用程序,并且在部署到 Firebase 时无法让服务器端工作.当应用在本地使用 IIS Express 运行时,服务器端/Firestore 代码工作正常。
在 VS 中发布时,我只发布了服务器项目,因为客户端文件与它一起链接和发布。部署后,任何客户端代码都可以正常工作,但与 Firestore 相关的任何代码都无法正常工作(因为 API 控制器位于服务器项目中)。
我已经搜索了有关该主题的每篇文章,但大多数都已经过时,因为 Blazor WASM 自预览以来发生了很大变化。
有人成功过吗?我是否遗漏了一个步骤,还是 Firebase 没有设置为使用 ASP.NET/Blazor 服务器端的东西?
这是我的 Startup.cs 以防万一 - 它几乎只是 Blazor WebAssembly ASP.NET Core 托管模板提供的默认模板:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Linq;
namespace G01ElectronicVoting.Server
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddRazorPages();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebAssemblyDebugging();
}
else
{
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.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
endpoints.MapFallbackToFile("index.html");
});
}
}
}
编辑:这一切都是为了避免为 Azure 付费
答案 0 :(得分:2)
Firebase 托管本身仅提供静态资产,不会解释其服务器上的任何文件。
Firebase 托管是 integrated with Cloud Functions,通过它您可以运行支持的任何语言(目前仅 Node.js)。
Firebase 托管也是 integrated with Google Cloud Run,它支持更广泛的运行时。我什至在这些 search results 中看到有人提到运行 .NET Core,所以这可能是您前进的最佳途径。