azure - 使用客户端、服务器部署解决方案并共享到 azure(Blazor wasm、.net core api)
问题描述
这是我的客户程序.cs:
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.Services.AddHttpClient("TurismoCascais.ServerAPI", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
// Supply HttpClient instances that include access tokens when making requests to the server project
builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("TurismoCascais.ServerAPI"));
builder.Services.AddApiAuthorization();
await builder.Build().RunAsync();
}
这是服务器启动.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDatabaseDeveloperPageExceptionFilter();
services.AddDefaultIdentity<ApplicationUserModelDB>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUserModelDB, ApplicationDbContext>();
services.AddAuthentication()
.AddIdentityServerJwt();
services.AddControllersWithViews();
services.AddRazorPages();
services.AddAutoMapper(typeof(Startup));
...
}
// 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.UseMigrationsEndPoint();
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.UseIdentityServer();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
endpoints.MapFallbackToFile("index.html");
});
}
最好的方法是什么?如何在 azure devops 上发布此解决方案?我应该发布服务器应用程序,然后是客户端应用程序吗?我尝试使用 azure 静态 Web 应用程序,但当客户端尝试与服务器通信时出现此错误:
需要帮忙...
我右键单击服务器项目并选择发布:选择 Azure 和 Windows 应用程序服务,配置 Azure SQL DB,然后控制台输出为:
Publish Succeeded.
Web App was published successfully http://turismocascaisapp.azurewebsites.net/
========== Build: 3 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========
Installation of Web App Site extension Microsoft.AspNetCore.AzureAppServices.SiteExtension is in progress...
Restarting the Web App...
Successfully installed Web App extension Microsoft.AspNetCore.AzureAppServices.SiteExtension
Successfully restarted Web App.
然后浏览器弹出:
评论了 HTTPSRedirect,因为我没有证书并且仍然无法正常工作..
解决方案
这不是答案,但没有其他方法可以共享此信息。
我刚刚构建并部署了一个标准模板 Web 程序集项目到 Azure。
您可以在此处查看该站点- https://blazor-cascais.azurewebsites.net/
并在 Github 上作为Repo站点。
如果不看你的代码,社区就无能为力了。
推荐阅读
- javascript - 如何从动态复选框中选择单个复选框
- apache-spark - EMR-5.32.0 上的 Spark 未生成请求的执行程序
- jsf - 如何重置 PrimeFaces 动态列的排序?
- sql-server - 包含嵌套对象的 XML 存在问题到 POCO(反)序列化(VB.Net)
- python - 获取TypeError:**或pow()不支持的操作数类型:'builtin_function_or_method'和'int'在Python中求解方程时
- postgresql - 编写一个触发器函数以根据 postgresql 中同一表中的另一个列值更新列值
- typo3 - TYPO3 9.5 扩展生成器抛出异常
- regex - 在电话号码 077 12345678 中包含空格
- excel - VBA 错误 1004 选择工作表范围失败
- python - 创建接收实时异步提要的 Python 数据可视化网站的方法