0

I have made a boilerplate .net 5.0 react SPA (I didnt do anything to it, literally just the boilerplate from dotnet), and then tried to publish it to Azure devops. I have created the app service, and the sql database and everything seemed to work, however I get a 500 status error when I try to load the page, saying the page cannot handle the request. I have the logs attached here, perhaps someone can make some better sense of this and let me know what I am missing? It seems like something to do with signing credentials, and I don't even know what that is at this point. I think I am really in over my head but really want to learn.

Page 1

enter image description here

Edit: Added the startup file

using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI;
using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using SpaTest.Data;
using SpaTest.Models;

namespace SpaTest {
    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.
        public void ConfigureServices( IServiceCollection services ) {
            services.AddDbContext<ApplicationDbContext>( options =>
                 options.UseSqlServer(
                     Configuration.GetConnectionString( "DefaultConnection" ) ) );

            services.AddDatabaseDeveloperPageExceptionFilter();

            services.AddDefaultIdentity<ApplicationUser>( options => options.SignIn.RequireConfirmedAccount = true )
                .AddEntityFrameworkStores<ApplicationDbContext>();

            services.AddIdentityServer()
                .AddApiAuthorization<ApplicationUser, ApplicationDbContext>();

            services.AddAuthentication()
                .AddIdentityServerJwt();

            services.AddControllersWithViews();
            services.AddRazorPages();

            // In production, the React files will be served from this directory
            services.AddSpaStaticFiles( configuration => {
                configuration.RootPath = "ClientApp/build";
            } );
        }

        // 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();
            } 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.UseStaticFiles();
            app.UseSpaStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseIdentityServer();
            app.UseAuthorization();
            app.UseEndpoints( endpoints => {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}" );
                endpoints.MapRazorPages();
            } );

            app.UseSpa( spa => {
                spa.Options.SourcePath = "ClientApp";

                if ( env.IsDevelopment() ) {
                    spa.UseReactDevelopmentServer( npmScript: "start" );
                }
            } );
        }
    }
}
  • can you post the startup.cs file ? – Thiago Custodio Aug 11 '21 at 16:32
  • Absolutely, added it in the main post. It is the boilerplate only, I have not changed anything. – superuhrich Aug 11 '21 at 17:07
  • i couldn't find anything wrong. Seems to me some service is not registered in your Startup.cs which gave you the null reference from the error log, but as you said, this is just boilerplate. I would comment services.AddDbContext block, services.AddDatabaseDeveloperPageExceptionFilter, services.AddDefaultIdentity, and publish a new version. Then, uncomment one by one to figure out which one is raising the error – Thiago Custodio Aug 11 '21 at 17:53
  • Upon further investigation, the release version running locally also gives the same 500 error response that I got when deploying to Azure. So not sure if that gives some better implication of what may be causing the issue. – superuhrich Aug 11 '21 at 19:57
  • really hard to help as I cannot reproduce this error ... – Thiago Custodio Aug 11 '21 at 20:00
  • try to upload what you have to a public github repo – Thiago Custodio Aug 11 '21 at 20:00
  • https://dev.azure.com/pauluhrich/_git/SPATest – superuhrich Aug 11 '21 at 20:45

2 Answers2

0

Thanks @ ctrldot for your insights.

Try to add application insights or Add error handling techniques to your App. Which is used to find the cause of the issue.

Check the Config file and Startup code if it is causing any issue.

You can use KUDU console by targeting https://sitename.scm.azurewebsites.net . You will be able to navigate in the debugging console to see the RAW logs from IIS. See KUDU for more info.

Refer here for more info

Delliganesh Sevanesan
  • 4,146
  • 1
  • 5
  • 15
0

So I finally figured it out. That boilerplate uses Identity Server 4, which requires having a self signed certificate either in the solution itself, or stored in Azure, as well as having a B1 level app service subscription. Once this was sorted out, no issues whatsoever.