首页 > 解决方案 > 使用客户端、服务器部署解决方案并共享到 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,因为我没有证书并且仍然无法正常工作..

标签: azureasp.net-coreazure-web-app-serviceblazoridentity

解决方案


这不是答案,但没有其他方法可以共享此信息。

我刚刚构建并部署了一个标准模板 Web 程序集项目到 Azure。

您可以在此处查看该站点- https://blazor-cascais.azurewebsites.net/

并在 Github 上作为Repo站点。

如果不看你的代码,社区就无能为力了。

在此处输入图像描述

在此处输入图像描述


推荐阅读