Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying IdentityServer4 Quickstart to Azure Web app returns 404 on index page but other routes work

I've deployed a project built from the quickstart from identityserver4 (https://github.com/IdentityServer/IdentityServer4.Demo). It works perfectly as long as I run it locally, but when I deploy it to Azure, the index page returns a 404, but when I manually go to other routes (like "/account/login") they work as expected.

My Startup.cs:

using System;
using System.Linq;
using System.Threading.Tasks;
using LunchBucks.Auth.Extensions;
using LunchBucksEncryption;
using LunchBucksEncryption.PasswordHashing;
using LunchBucksEncryption.SaltGeneration;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

namespace LunchBucks.Auth
{
    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient<ISaltGeneration, SaltGeneration>();
            services.AddTransient<IPasswordHashing, PasswordHashing>();
            services.AddTransient<IEncryptionManagement, EncryptionManagement>();
            services.AddMvc();

            services.AddIdentityServer()
                .AddDeveloperSigningCredential()
                .AddInMemoryApiResources(ApiResourceExtensions.GetApiResources())
                .AddInMemoryClients(ClientExtensions.GetClients())
                .AddInMemoryIdentityResources(ClientExtensions.GetIdentityResources())
                .AddLunchBucksUserStore();

            services.AddCors(options =>
            {
                options.AddPolicy("default", policy =>
                {
                    policy.WithOrigins("http://localhost:3000")
                        .AllowAnyHeader()
                        .AllowAnyMethod();
                    policy.WithOrigins("https://lunchbucks-frontend.azurewebsites.net")
                        .AllowAnyHeader()
                        .AllowAnyMethod();
                });
            });
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseCors("default");

            app.UseIdentityServer();

            app.UseStaticFiles();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });
            });
        }
    }
}

Program.cs:

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>();
}

Azure Web App default documents: enter image description here

The entire MVC applications folder structure with controllers and views is identical to the quickstart.

I have no idea what's going wrong here, as it's working locally, so any help would be appreciated :) Thanks in advance.

like image 319
sunero4 Avatar asked Dec 17 '18 19:12

sunero4


1 Answers

I found out what the issue was - quite simply I just wasn't paying attention. This is in the controller for the homepage when you just download the quickstart for some reason: enter image description here Sorry for the inconvenience and thanks for your help :)

like image 164
sunero4 Avatar answered Oct 02 '22 00:10

sunero4