Blazor Project Hierarchy
I currently have a server only Blazor project and I am trying to sorta start from scratch by making a new Blazor Project from a template and then put everything back where it's supposed to be. I'm making the project with both interactive modes, so it makes a
Portfolio
and a Portfolio.Client
project. Through assumption and looking around on the internet, everyone says that models and stuff should be in the server project, which makes sense. I'm having a problem referencing anything inside Porftolio
from Porftolio.Client
though, I try to add a project reference but everything I do won't let me reference my models if I store it in that project. If I put my anything inside the Portfolio.Client
project, I can reference it with no problem from Portfolio
, but I hear it's bad practice to put all that into the client.
I'm doing this because I'm using Identiy in my Blazor project which needs an HttpContext, and from what I'm reading, you can't get the HttpContext if you're in interactive mode. One of my components is turning interactive render mode off which shuts down my app bar and theme which is annoying, but also why I'm looking to move to a different way of handling the render mode.
I feel like I'm misunderstanding something. Any help would be greatly appreciated 🙂4 Replies
what's the exact question? You want to use httpcontext within context of the application?
Yeah sorry, I kinda have 2 questions going there.
The main problem I'm having is trying to get my
/Account/
pages to work with an Interactive render mode. I'm just reading the comments on this AccountsLayout.razor
that came with the template that says
So it's then transitioned into a server-rendered page, and all my buttons and interactive components stop working because of that transition.
I tried to restart and make a new project with the Auto
rendering mode, but I was having the reference issues.
I'm either trying to find a way to fix that referencing issue, or find a way to keep my interactive render mode while keeping that HttpContext.as long as you are using Microsoft Identity, you cannot have interactive components in your login pages. You can style the pages just like the rest of your app but the only option you have for interactivity would be using Edit Forms or javascript https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-8.0#area-folder-of-static-ssr-components
Auto simply switches between server side rendering and client side rendering, your account pages will still use server side rendering
Ahhh okay thanks for the help! I'll read through that and decide what to do next 🙂