0

I copied the IdentityServer4 quick start views to my project i can confirm the code is breaking in the AccountController.

However i cannot for life of me figure our how to resolve this problem The view 'Login' was not found. Searched locations: /Views/Account/Login.cshtml, /Views/Shared/Login.cshtml

Here is the Quick Start i copied the folders from https://github.com/IdentityServer/IdentityServer4.Quickstart.UI

public class Program
    {
        public static int Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .Enrich.FromLogContext()
                .WriteTo.Console()
                .CreateLogger();

            IdentityModelEventSource.ShowPII = true;

            try
            {
                Log.Information("Starting host...");
                CreateWebHostBuilder(args).Build().Run();
                return 0;
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly.");
                return 1;
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .UseUrls("http://localhost:4000");
    }
public class Startup
    {
        public IWebHostEnvironment Environment { get; }
        public IConfiguration Configuration { get; }

        public Startup(IWebHostEnvironment environment, IConfiguration configuration)
        {
            Environment = environment;
            Configuration = configuration;
        }

        public void ConfigureServices(IServiceCollection services)
        {
            // https://github.com/IdentityServer/IdentityServer4.Quickstart.UI#quickstart-ui-for-identityserver4
            services.AddControllersWithViews();

            var builder = services.AddIdentityServer(options =>
                {
                    options.Events.RaiseErrorEvents = true;
                    options.Events.RaiseInformationEvents = true;
                    options.Events.RaiseFailureEvents = true;
                    options.Events.RaiseSuccessEvents = true;

                    // see https://identityserver4.readthedocs.io/en/latest/topics/resources.html
                    options.EmitStaticAudienceClaim = true;
                })
                .AddInMemoryClients(Config.Clients)
                .AddInMemoryIdentityResources(Config.IdentityResources)
                //.AddInMemoryApiResources(new List<ApiResource>())
                .AddInMemoryApiScopes(Config.ApiScopes)
                .AddTestUsers(TestUsers.Users)
                .AddDeveloperSigningCredential();
        }

        public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseDeveloperExceptionPage();
            
            app.UseStaticFiles();
            app.UseRouting();

            app.UseIdentityServer();
            app.UseAuthorization();

            app.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
        }
    }

Project Structure

enter image description here

Exception enter image description here

Note i was missing the files in Debug. But i have updated my csproj and now they are there

enter image description here

Ricardo Saracino
  • 979
  • 2
  • 12
  • 28

1 Answers1

0

so this seems to work

I needed to add this to my csproj

<ItemGroup>
    <Content Include="appsettings.json" CopyToOutputDirectory="Always" />
    <Content Include="Views\**\*" CopyToOutputDirectory="Always" />
    <Content Include="wwwroot\**\*" CopyToOutputDirectory="Always" />
</ItemGroup>

I also had to update my Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    services
        .AddControllersWithViews()
        .AddRazorRuntimeCompilation();
   
    ....
}

reference to solution https://blog.elmah.io/add-razor-runtime-compilation-when-developing-asp-net-core/

Something to note enter image description here

Ricardo Saracino
  • 979
  • 2
  • 12
  • 28