与客户端,服务器和共享解决方案一起部署解决方案(Blazor wasm,.net核心api) [英] Deploy solution with client, server and shared to azure (Blazor wasm, .net core api)
问题描述
这是我的解决方案:
这是我的客户端程序.cs:
公共静态异步任务Main(字符串[] 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>();//向服务器项目发出请求时,提供包含访问令牌的HttpClient实例builder.Services.AddScoped(sp => sp.GetRequiredService< IHttpClientFactory>().CreateClient("TurismoCascais.ServerAPI"));builder.Services.AddApiAuthorization();等待builder.Build().RunAsync();}
这是服务器启动.cs:
public void ConfigureServices(IServiceCollection服务){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));...}//此方法由运行时调用.使用此方法来配置HTTP请求管道.公共无效配置(IApplicationBuilder应用程序,IWebHostEnvironment env){如果(env.IsDevelopment()){app.UseDeveloperExceptionPage();app.UseMigrationsEndPoint();app.UseWebAssemblyDebugging();}别的{app.UseExceptionHandler("/Error");//HSTS的默认值为30天.您可能要针对生产方案更改此设置,请参见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发行版上发布此解决方案?我应该发布服务器应用程序,然后发布客户端应用程序吗?我尝试使用azure静态Web应用程序,但是当客户端尝试与Server通信时出现此错误:
需要帮助...
我右键单击Server项目,然后选择发布:选择Azure和Windows应用服务,配置Azure SQL DB,然后控制台输出为:
发布成功.Web App已成功发布http://turismocascaisapp.azurewebsites.net/==========构建:3成功,0失败,0最新,跳过0 ====================发布:1成功,0失败,0跳过===========Web App网站扩展Microsoft.AspNetCore.AzureAppServices.SiteExtension的安装正在进行中...重新启动Web App ...成功安装Web应用程序扩展Microsoft.AspNetCore.AzureAppServices.SiteExtension成功重新启动Web App.
然后浏览器弹出:
评论了HTTPSRedirect,因为我没有证书,但仍然无法正常工作..
这不是答案,但是没有其他共享此信息的方法.
我刚刚构建了一个标准模板Web Assembly项目并将其部署到Azure.
您可以在
This is my solution:
This is my client program.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();
}
this is the server startup.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");
});
}
What is the best way and how can I publish this solution on azure devops? Should I publish server application, then client application? I tried using azure static web apps but I get this error when client tries communicate with Server:
Need help...
I right clicked in the Server project and choosed publish: Choosed Azure and windows app service, configured Azure SQL DB then the console output was:
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.
And the browser poped up:
Commented HTTPSRedirect because I dont have certificade and still doesnt work..
This isn't an answer, but there's no other way to share this info.
I've just built and deployed a standard template Web Assembly project to Azure.
You can see the site here - https://blazor-cascais.azurewebsites.net/
And site as a Repo on Github.
Without a look at your code there's not a lot else the community can do.
这篇关于与客户端,服务器和共享解决方案一起部署解决方案(Blazor wasm,.net核心api)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!