Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor - .NET 8.0 - InvalidOperationException: Cannot find the fallback endpoint specified by route values: { page: /_Host, area: }

$
0
0

I am programming a website in the .NET framwork Blazor (.NET 8.0). I wanted to add an login via Active Directory and after this I got the following error:

System.InvalidOperationException: Cannot find the fallback endpoint specified by route values: { page: /_Host, area:  }.   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DynamicPageEndpointMatcherPolicy.ApplyAsync(HttpContext httpContext, CandidateSet candidates)   at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.SelectEndpointWithPoliciesAsync(HttpContext httpContext, IEndpointSelectorPolicy[] policies, CandidateSet candidateSet)   at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatch|10_1(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matchTask)   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

After long searching through the internet I found a solution for the problem but it didnt worked for me. The solution was the following one:

<PropertyGroup><UseRazorSourceGenerator>false</UseRazorSourceGenerator></PropertyGroup>`

This should be added to the project.csproj.Maybe someone can tell me what my mistake is and help me to solve it.

_Host.cshtml:

@page "/"@namespace Berhub@using Berhub.Pages@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers@{    Layout = null;}<!DOCTYPE html><html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>BERHub</title><base href="~/" /><link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" /><link href="css/app.css" rel="stylesheet" /></head><body><app><component type="typeof(App)" render-mode="ServerPrerendered" /></app><script src="_framework/blazor.server.js"></script></body></html>

Program.cs:

using Berhub;using Berhub.Models;using berhub.Components;using Dapper;using Berhub.DataAccessLayer.DataAccessLayer;using Berhub.DataAccessLayer.SqlDataAccess;using Radzen;using Radzen.Blazor;using Microsoft.Extensions.DependencyInjection;using Berhub.DataAccessLayer.Repositories;using Microsoft.AspNetCore.Authentication.Negotiate;using Microsoft.AspNetCore.Authorization;using Microsoft.Extensions.Configuration;var builder = WebApplication.CreateBuilder(args);// Add services to the container.builder.Services.AddRazorPages();builder.Services.AddServerSideBlazor();builder.Services.AddRazorComponents()    .AddInteractiveServerComponents();builder.Services.AddRadzenComponents();builder.Services.AddScoped<IWindowsServerData, WindowsServerData>();builder.Services.AddScoped<ISqlDataAccess, SqlDataAccess>();builder.Services.AddScoped<IHostnameData<HostnameModel>, HostnameData>();builder.Services.AddScoped<IAppointment<Appointment>, Berhub.DataAccessLayer.DataAccessLayer.AppointmentData>();var configuration = builder.Configuration;builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();            // Windows authentication  may not be applied with Kestrel without this line                    builder.Services.AddAuthorization(    options =>{    options.AddPolicy("KeyUsers", policy =>    policy.RequireRole(configuration.GetSection("ActiveDirectory")["KeyUsers"]));});/**builder.Services.AddRazorPages(options =>{    options.RootDirectory = "/Components";});**/builder.Services.AddServerSideBlazor();var app = builder.Build();// Configure the HTTP request pipeline.if (!app.Environment.IsDevelopment()){    app.UseExceptionHandler("/Error", createScopeForErrors: true);    app.UseHsts();}app.UseHttpsRedirection();app.UseStaticFiles();app.UseAntiforgery();app.UseRouting();app.UseAuthentication();app.UseAuthorization();app.MapRazorPages();app.MapBlazorHub();app.MapFallbackToPage("/_Host"); // Pfad zur _Host.cshtml anpassenapp.Run();

index.razor (login):

@page "/"@attribute [StreamRendering]<PageTitle>Home</PageTitle><AuthorizedView Policy="KeyUsers"><Authorized></Authorized><NotAuthorized><link rel="stylesheet" href="Login.razor.css" /><div class= "container"><form method = "post"><fieldset><legend>Anmelden</legend><div class="nutznername"><label for="username">Benutzername: </label><input type="text" name="username" value=""/></div><div class="passwort"><label for="password">Passwort: </label><input type="password" name="password"></div><div class="bestätigen"><label>&nbsp;</label><input type="submit" value="Submit" class="submit" /></div></fieldset></form> </div></NotAuthorized></AuthorizedView>

The Pictures shows the project structure of my project.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>