Casey Crookston
Casey Crookston

Reputation: 13965

Error when using [Authorize]

I am getting this error:

The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Scripts".

I only get this error when I put [Authorize] on the home controller.

    [Authorize]
    public ViewResult Index()
    {
        return View();
    }

To trouble shoot, I have stripped the _layout page of all but this:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 </head>
 <body>
     <div class="container body-content">
         @RenderBody()
     </div>
</body>
</html>

And the Index view for Home is nothing but this:

hello world

If I remove [Authorize], then there is no error.

Upvotes: 0

Views: 71

Answers (1)

Francisco
Francisco

Reputation: 4101

Your original view has a "Scripts" section declared. You need to either remove that or add this code to your layour page:

@RenderSection("scripts", required: false)

Upvotes: 2

Related Questions