Error Accessing a User in Blazor
I am trying to setup my first Blazor project after being away from dotnet for a while to chase the javsacript world and I am completely stuck on something simple.
I have created a new blazor app with the template and enabled Individual Accounts for auth. I am simply trying to get the current user information for the home screen and I get an error :
The browser console has the error:
I have tried to do everything I can find about this. I have tried changing render modes, etc. I am at a complete loss.
The home page is simply this (which I based on the sample account pages)
I have put the entire repo here:
https://github.com/jmarbutt/ExampleIssues/tree/main/ExampleIssues
GitHub
ExampleIssues/ExampleIssues at main · jmarbutt/ExampleIssues
Contribute to jmarbutt/ExampleIssues development by creating an account on GitHub.
18 Replies
strange, I couldn't repro this. I cloned your repo and dont get any console errors. Once in a while I do get an error here because httpcontext is null, which isnt consistent
i am curious how httpcontext gets created here since in the program.cs I see you only injected httpcontextaccessor and dont seem to use it
login logic seems to work fine too
I played around with app.razor because it didn't seem to make sense to me, give this a shot.
removed render mode from headoutlet, injected navmanager instead of httpcontext since that can be null in a prod enviroment
I replaced my App.razor with that and it just goes in a loop of reloading
If you login and go to the home page, it just loops
I just created a new blank project again, and the only thing i changed was the home page
to match this:
how does httpcontext get created in the scope of the current application? That's what im wondering
right, I tried adding:
and no go
But if you go to the page https://localhost:7126/Account/Manage it is obviously working
Maybe I am completely going this the wrong way, I just need to get my current user so I can ensure it is filtered down to their data
no idea what's different between our env. I managed to login fine and get context of the user
I tried it on another computer and the same thing from a completely new project and made sure the only thing I did was replace the Home.razor
https://gbr1b886-7097.usw3.devtunnels.ms/ I created a tunnel of my env, only thing that doesnt work is the counter/weather component. Didn't really change much either
User: [email protected]
Pass: Test123!
yeah that is working
I can push it to a repo and you can clone it, see if that works?
yeah lets try that
its bizarre that your env isn't working with the same code though
GitHub
GitHub - friedice5467/ExampleIssues
Contribute to friedice5467/ExampleIssues development by creating an account on GitHub.
yeah yours is working let me see if I can find the differences
I think I modified only app.razor and home.razor
Which shouldn't really have done much in the scheme of things
So I found that it is something wrong with safari and the cookies or storage on my machine, I cleaned everything and it is running fine