0

This is my solution: enter image description here

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:

enter image description here

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:

enter image description here

Commented HTTPSRedirect because I dont have certificade and still doesnt work..

MarchalPT
  • 1,268
  • 9
  • 28
  • There are many articles if you search for "publishing blazor Web Assembly to Azure". Have you checked these out? The MsDocs one is here: https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/webassembly?view=aspnetcore-5.0 – MrC aka Shaun Curtis Apr 19 '21 at 15:06
  • @MrCakaShaunCurtisYes I did that already, deployed the server project with Visual Studio as a App Service but doesnt work, gives me code 500... And I was wondering if there was a way of publishing every project at once instead of project by project.. – MarchalPT Apr 19 '21 at 15:25
  • 1
    You don't deploy multiple projects. If your setup is correct and runs locally you just deploy the Server Project. A static deployment means there's no Server component, just a service point to provide the files for the WASM SPA to start. It looks like you have an API Server - I can see a Controller Directory, etc., so you probably need to deploy to an App Service. You deploy the server project to the App Service and it deploys all the code necessary. – MrC aka Shaun Curtis Apr 19 '21 at 15:41
  • @MrCakaShaunCurtis Thanks didnt know that deploying the Server, would deploy everything, Im doing that just now but it is taking a long time in the Dependency configuration progress. Before I tryed with SQL Server DB and wasnt working, right now is configuring the Azure SQL Database and is on it like for 40 mins, dont know if its supposed to take that long or if it is blocked somewhere.. – MarchalPT Apr 19 '21 at 15:56
  • @MrCakaShaunCurtis its not working, Dependency configuration had crashed, so I redoo the whole process then made publish, then the browser poped up with a http code 500.. – MarchalPT Apr 19 '21 at 16:27
  • There doesn't look anything wrong with the deployment process itself. Your problem probably lies in resource access from the AppService. I'm assuming your application runs locally in debug mode? Does Index come up? At this point you're going to need to go through a step process to resolve the issue. Deploy a standard Template Blazor WASM app. Get that working then add your DB connection with a basic test ,..... Not what you want to hear, but... It will probably be something simple. We've all been there! – MrC aka Shaun Curtis Apr 19 '21 at 16:41
  • @MrCakaShaunCurtis yes my app runs locally with no problems, when I publish, it asks for me to insert the DefaultConnection string, locally its in the appsettings.json file, dont know if that makes a difference.. I will try to deploy a standart template.. – MarchalPT Apr 19 '21 at 16:47
  • @MrCakaShaunCurtis just tried with a standart template and doenst work, gives code 500.. – MarchalPT Apr 20 '21 at 08:43
  • You should investigate that 500. Might be something with the ConnectionString. You didn't detail "configured Azure SQL DB" or how you intend to migrate the Db. – H H Apr 22 '21 at 11:53
  • @HenkHolterman it had to do with certificate – MarchalPT Apr 22 '21 at 12:31

1 Answers1

1

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.

enter image description here

enter image description here

MrC aka Shaun Curtis
  • 19,075
  • 3
  • 13
  • 31