{"record":{"id":"8572b8b3da9a3a31","repo":"dotnet/aspnetcore","slug":"do-not-specify-both-authorized-and-childcontent","errorCode":null,"errorMessage":"Do not specify both 'Authorized' and 'ChildContent'.","messagePattern":"Do not specify both 'Authorized' and 'ChildContent'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Authorization/src/AuthorizeViewCore.cs","lineNumber":80,"sourceCode":"        {\n            var authorized = Authorized ?? ChildContent;\n            builder.AddContent(0, authorized?.Invoke(currentAuthenticationState!));\n        }\n        else\n        {\n            builder.AddContent(0, NotAuthorized?.Invoke(currentAuthenticationState!));\n        }\n    }\n\n    /// <inheritdoc />\n    protected override async Task OnParametersSetAsync()\n    {\n        // We allow 'ChildContent' for convenience in basic cases, and 'Authorized' for symmetry\n        // with 'NotAuthorized' in other cases. Besides naming, they are equivalent. To avoid\n        // confusion, explicitly prevent the case where both are supplied.\n        if (ChildContent != null && Authorized != null)\n        {\n            throw new InvalidOperationException($\"Do not specify both '{nameof(Authorized)}' and '{nameof(ChildContent)}'.\");\n        }\n\n        if (AuthenticationState == null)\n        {\n            throw new InvalidOperationException($\"Authorization requires a cascading parameter of type Task<{nameof(AuthenticationState)}>. Consider using {typeof(CascadingAuthenticationState).Name} to supply this.\");\n        }\n\n        // Clear the previous result of authorization\n        // This will cause the Authorizing state to be displayed until the authorization has been completed\n        isAuthorized = null;\n\n        currentAuthenticationState = await AuthenticationState;\n        isAuthorized = await IsAuthorizedAsync(currentAuthenticationState.User);\n    }\n\n    /// <summary>\n    /// Gets the data required to apply authorization rules.\n    /// </summary>","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Authorization/src/AuthorizeViewCore.cs#L62-L98","documentation":"Thrown by AuthorizeViewCore.OnParametersSetAsync when both the 'Authorized' and 'ChildContent' RenderFragment parameters are non-null on an AuthorizeView-derived component. These two parameters are semantically equivalent (both render when the user is authorized); 'ChildContent' exists for convenience and 'Authorized' for symmetry with 'NotAuthorized'. The framework treats specifying both as a configuration error because the intent is ambiguous.","triggerScenarios":"Setting both <ChildContent> and <Authorized> child content on the same <AuthorizeView> element in Razor markup, or assigning both ChildContent and Authorized properties programmatically. The check runs on every parameter set cycle (AuthorizeViewCore.cs:78-81).","commonSituations":"A developer adds an <Authorized> template to an existing <AuthorizeView> that already uses its default child content (ChildContent), forgetting to remove the original. Also happens when refactoring from simple to explicit authorized/not-authorized templates.","solutions":["Remove one of the two: use either ChildContent OR Authorized, never both.","If you need explicit NotAuthorized/Authorizing templates alongside authorized content, switch to using <Authorized> and drop the unnamed child content.","If you only need simple authorized display, keep ChildContent and remove the <Authorized> element."],"exampleFix":"// before\n<AuthorizeView>\n    <Authorized>\n        <p>You are signed in.</p>\n    </Authorized>\n    <ChildContent>\n        <p>You are signed in.</p>\n    </ChildContent>\n</AuthorizeView>\n\n// after\n<AuthorizeView>\n    <Authorized>\n        <p>You are signed in.</p>\n    </Authorized>\n    <NotAuthorized>\n        <p>Please sign in.</p>\n    </NotAuthorized>\n</AuthorizeView>","handlingStrategy":"validation","validationCode":"// Before rendering, ensure not both are set\nif (authorizeView.Authorized != null && authorizeView.ChildContent != null)\n{\n    throw new InvalidOperationException(\"Specify only one of Authorized or ChildContent.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In markup, choose one approach per AuthorizeView: either unnamed child content or explicit <Authorized>.","When adding <Authorized>/<NotAuthorized> templates, remove the unnamed child content block."],"tags":["blazor","authorization","authorizeview","configuration"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}