【发布时间】:2021-05-20 21:44:23
【问题描述】:
我正在使用连接到 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 付费
【问题讨论】:
标签: firebase google-cloud-firestore blazor blazor-webassembly