question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor WebAssembly Identity scaffolding issues

See original GitHub issue

Blazor webassembly version: dotnet new -i Microsoft.AspNetCore.Components.WebAssembly.Templates::3.2.0-preview5.20216.8

Creating new project blazer web assembly with Authentication and asp.netcore hosted

after Scaffold applied for Identity, I am getting the error: invalidOperationException: The following sections have been defined but have not been rendered by the page at ‘/Pages/Shared/_Layout.cshtml’: ‘Scripts’. To ignore an unrendered section call IgnoreSection(“sectionName”).

it will “fix” if I change: Server/Page/Shared/_Layout.cshtml

remove:

@section Scripts {
    @RenderSection("Scripts", required: false)
}

and replace for:

@{
    @if (IsSectionDefined("Scripts"))
    {
        IgnoreSection("Scripts");
    }
}

however the JS wont be populated from pages using this template via:

@section Scripts {
    <partial name="_ValidationScriptsPartial" />
}

I am missing any configuration to get that sorted?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

5reactions
danroth27commented, Jun 13, 2020

~@deepchoudhery It looks like the Identity scaffolder generates a layout into the server project that doesn’t render the Scripts section used by the Identity pages to add required scripts to the page.~

Correction: The problematic layout comes from the Blazor WebAssembly template, not from the scaffolder.

The generated Pages/Shared/_Layout.cshtml looks like this:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>@ViewBag.Title</title>
    <link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
    <link href="~/css/app.css" rel="stylesheet" />
</head>

<body>
    <div class="main">
        <div class="content px-4">
            @RenderBody()
        </div>
    </div>
</body>

</html>

But it needs to render the Scripts section like this:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>@ViewBag.Title</title>
    <link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
    <link href="~/css/app.css" rel="stylesheet" />
</head>

<body>
    <div class="main">
        <div class="content px-4">
            @RenderBody()
        </div>
    </div>

    @RenderSection("Scripts", required: false)
</body>

</html>
0reactions
danroth27commented, Jun 13, 2020

@HaoK Whoops! You’re right. I need to work on my diff’ing skills 😝

There is a default minimalistic layout in the Blazor WebAssembly server project that doesn’t render the Scripts section. Looks like we need to address the layout issue in the Blazor WebAssembly template. Closing this issue as a dup of https://github.com/dotnet/aspnetcore/issues/22712. I’ll open a separate issue for the view imports issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error scaffolding identity in blazor webassembly app
I am building a webassembly project in Razor using Visual Studio 2019 (version 16.9.4) and whenever I try to scaffold the identity I...
Read more >
Blazor WebAssembly Add Identity Scaffolding · Issue #22712
After creating a new Blazor WebAssembly app then adding Identity Scaffolding. Next, run the app and goto the Fetch page and receive exception:...
Read more >
Scaffolding failing for identity in blazor - Microsoft Q&A
When I try to add identity thru the cli cause the tooling is broken form the gui I get this error. I am...
Read more >
Need Input Regarding Authentication/Identity for New ...
I went through the process of scaffolding all the Identity files, that process introduced several issues which were really annoying to fix ...
Read more >
Identity with a .NET 6 Web API & Blazor WebAssembly
NET 6 Web API & Blazor WebAssembly 03:39 Create the Project 06:11 ... a User 21:20 Scaffolding Identity Files 27:33 Add a Relationship...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found