blazor-workshop icon indicating copy to clipboard operation
blazor-workshop copied to clipboard

Status Code Different

Open ToiWright opened this issue 4 years ago • 4 comments

I am working through the Authentication tutorial and I have just added the [Authorize] attribute. I can no longer view my orders, but instead of getting a 302 as is indicated in the documentation, I am getting a 304 on myorders and a 401 on orders.

ToiWright avatar May 08 '20 14:05 ToiWright

The issue is that the App.razor file in 00-get-started does not match the one in 06. It is missing the RedirectToLogin.

ToiWright avatar May 08 '20 15:05 ToiWright

In order to get Authentication to work I added the RedirectToLogin.razor page and I updated the app.razor page from the Blazor WebAssembly template.

<CascadingAuthenticationState>
    <Router AppAssembly="@typeof(Program).Assembly">
        <Found Context="routeData">
            <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
                <NotAuthorized>
                    @if (!context.User.Identity.IsAuthenticated)
                    {
                        <RedirectToLogin />
                    }
                    else
                    {
                        <p>You are not authorized to access this resource.</p>
                    }
                </NotAuthorized>
            </AuthorizeRouteView>
        </Found>
        <NotFound>
            <LayoutView Layout="@typeof(MainLayout)">
                <p>Sorry, there's nothing at this address.</p>
            </LayoutView>
        </NotFound>
    </Router>
</CascadingAuthenticationState> 

ToiWright avatar May 08 '20 15:05 ToiWright

I see that you made the same changes later in the session. Interesting...

ToiWright avatar May 08 '20 17:05 ToiWright

@ToiWright #253 should have fixed your issue. Can you check and close this issue (i.e. #251)? Thanks.

lohithgn avatar Dec 20 '21 10:12 lohithgn