chanan / BlazorStrap

Bootstrap 4 Components for Blazor Framework
https://blazorstrap.io
The Unlicense
917 stars 157 forks source link

AuthorizeView Issue #149

Closed endeffects closed 5 years ago

endeffects commented 5 years ago

I have surrounded some of my controls with an AuthorizeView. With the latest version of BlazorStrap i receiving the following error:

Error RZ9999 The child content element 'ChildContent' of component 'BSForm' uses the same parameter name ('context') as enclosing child content element 'Authorized' of component 'AuthorizeView'. Specify the parameter name like: '<ChildContent Context="another_name"> to resolve the ambiguity

<AuthorizeView Policy="@Policies.IsUser">
    <Authorized>
        <BSForm>
            ...
        </BSForm>
    </Authorized>
</AuthorizeView>
chanan commented 5 years ago

@jbomhold3 I think thats a "problem" in the way Blazor does cascading values... I put the word problem is quotes because I doubt they will fix it.

Should we just go and prefix all our cascading values with "BS"?

jbomhold3 commented 5 years ago

After playing around with this some. This is not a blazorstrap issue. It happens with the default EditForm. This can be fixed easily


<Authorized context="Auth"> @Auth.User..... </Authorized>
jbomhold3 commented 5 years ago

Checking into the matter more this is Blazors Default behavior when dealing with a RenderFragment. They automagically generate a context for each. If you nest them your creating the ambiguous issue. Changing the context name in any of the components will resolve the issue

chanan commented 5 years ago

Based on the information @jbomhold3 found out about Cascading Values with RenderFragment, we are closing this issue

endeffects commented 5 years ago

Ah thank you, i did not noticed this and i found nothing related to the error code.

endeffects commented 5 years ago

One more question about the context issue, won't it make sense to use a custom context name within the BlazorStrap RenderFragments by default? The chance that this happens for other users seems to be high and you could prevent this easily?

chanan commented 5 years ago

We can't we don't use the name "context" at all - when we use RenderFragment - Blazor auto creates behind the scene a variable named context, but they use the same variable everytime which causes your error. That is a bug in Blazor if you ask me, they should use different names - so one day they might fix it...

endeffects commented 5 years ago

Oh ok, I just thought you are able to override it on a lower level as suggested.

chanan commented 5 years ago

Yes that’s what I thought too when I first read the issue but after more investigation by John we found that is not the case. Sadly.

jbomhold3 commented 5 years ago

RenderFragment to be more clear. For anyone finding this issue later on. Renaming the auth context is probably the easiest bet as your likely to run into the issue with other things. This also affects Microsoft's Editform component.

shahedc commented 4 years ago

After playing around with this some. This is not a blazorstrap issue. It happens with the default EditForm. This can be fixed easily

<Authorized Context="Auth"> @Auth.User..... </Authorized>

Btw, the attribute Context is case-sensitive, so a lower-case 'c' won't work when adding the context name. You must spell the word Context with an upper-case 'C'.

Manzoliz commented 4 years ago

just for the correct overall answer: <Authorized Context="Auth"> @Auth.User..... </Authorized>

geodeasic commented 1 year ago

@Manzoliz 's answer is by far the most accurate.