6

I have a asp.net 6 application I am trying to add a server side blazor component to. I have my program setup, I am calling my component but when I navigate to the page it cant find the static blazor file because its putting in the routing. How do I resolve this?

Also I can get static and ServerPrerendered render modes to work correctly just not Server as it requires the JS.

    builder.Services.AddRazorPages();
    builder.Services.AddServerSideBlazor();
    builder.Services.AddHttpContextAccessor();


    var app = builder.Build();

    // Configure the HTTP request pipeline.
    if (!app.Environment.IsDevelopment())
    {
        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.UseRouting();

    app.UseAuthorization();

    app.MapRazorPages();
    app.MapBlazorHub();
    app.Run();

_Layout.cshtml

<script src="~/_framework/blazor.server.js"></script>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)

Search Component Call:

<component type=typeof(ItemSearch) param-Search=Model.Search render-mode=Server />

On my index page:

Information: Normalizing '_blazor' to 'https://localhost:7216/_blazor'.

Once I search:

https://localhost:7216/Search/_blazor/initializers 404 
0

2 Answers 2

12

The solution is add base to the head. of _layout.cshtml

<head>
    <base href="~/"/> 
</head>
Sign up to request clarification or add additional context in comments.

Comments

0

I was able to solve this problem (already had the base tag) by deleting my project's obj folder and restarting Visual Studio.

1 Comment

This is not the cause

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.