可以使用 Firebase 托管使用服务器端功能的 Blazor 应用程序吗?
Can a Blazor app using server-side functionality be hosted with Firebase?
我正在使用连接到 Firestore 数据库的 ASP.NET 核心托管模型(所以 3 个项目:客户端、服务器、共享)使用 Blazor WebAssembly 开发一个应用程序,但在服务器端工作时遇到问题部署到 Firebase 时。 Server-side/Firestore 当应用程序 运行 在本地使用 IIS Express 时,代码工作正常。
在 VS 中发布时,我只发布服务器项目,因为客户端文件已链接并与其一起发布。部署后,任何客户端代码都可以正常工作,但与 Firestore 相关的任何代码都不能(因为 API 控制器在服务器项目中)。
我搜索了关于该主题的每篇文章,但大多数都已过时,因为自预览版以来 Blazor WASM 发生了很大变化。
有人成功过吗?我错过了一个步骤还是 Firebase 没有设置为与 ASP.NET/Blazor 服务器端的东西一起工作?
这是我的 Startup.cs 如果它有帮助 - 它几乎只是 Blazor WebAssembly ASP.NET 核心托管模板提供的默认模板:
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 托管本身仅提供静态资产,不会解释您在其服务器上的任何文件。
Firebase 托管是 integrated with Cloud Functions,通过它您可以运行 支持的任何语言(目前只有 Node.js)。
Firebase 托管也是 integrated with Google Cloud Run, which supports a much broader range of runtimes. I even see some mention of folks running .NET Core in these search results,因此这可能是您前进的最佳途径。
我正在使用连接到 Firestore 数据库的 ASP.NET 核心托管模型(所以 3 个项目:客户端、服务器、共享)使用 Blazor WebAssembly 开发一个应用程序,但在服务器端工作时遇到问题部署到 Firebase 时。 Server-side/Firestore 当应用程序 运行 在本地使用 IIS Express 时,代码工作正常。
在 VS 中发布时,我只发布服务器项目,因为客户端文件已链接并与其一起发布。部署后,任何客户端代码都可以正常工作,但与 Firestore 相关的任何代码都不能(因为 API 控制器在服务器项目中)。
我搜索了关于该主题的每篇文章,但大多数都已过时,因为自预览版以来 Blazor WASM 发生了很大变化。
有人成功过吗?我错过了一个步骤还是 Firebase 没有设置为与 ASP.NET/Blazor 服务器端的东西一起工作?
这是我的 Startup.cs 如果它有帮助 - 它几乎只是 Blazor WebAssembly ASP.NET 核心托管模板提供的默认模板:
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 托管本身仅提供静态资产,不会解释您在其服务器上的任何文件。
Firebase 托管是 integrated with Cloud Functions,通过它您可以运行 支持的任何语言(目前只有 Node.js)。
Firebase 托管也是 integrated with Google Cloud Run, which supports a much broader range of runtimes. I even see some mention of folks running .NET Core in these search results,因此这可能是您前进的最佳途径。