Aspnetcore: [Question][Blazor] Multiple blazor apps / _Host.cshtml

Created on 10 Mar 2020  路  4Comments  路  Source: dotnet/aspnetcore

I am creating system which should display base _Host.cshtml for non-employee users. Base _Host.cshtml has completely different layout, design, css, script files.

How to create another like _Host.cshtml file? Every request starting with "/admin" should redirect to this new _Host.cshtml. Also every page will have attribute requesting user policy.

How would you solve this? Thanks

Answered Resolved area-blazor blazor-wasm question

All 4 comments

@glararan thanks for contacting us.

  • Create a separate razor page and set the route to "/Admin"
  • Set the base tag href to "~/Admin/"
  • Call MapFallbackToPage("~/Admin/{*clientroutes:nonfile}", "/Admin")

@javiercn Thanks for reply! You should definitely add this into documentation as an example :)

@javiercn May I ask how should folder structure look like? Kinda figuring out how to get it working. In src directory should be folder "Admin"?

Currently my file structure looks like
Pages/...razor files
Pages/Account/..razor files
Pages/Admin/Admin.cshtml (page "/Admin")
Pages/Admin/AdminLayout.razor
Pages/Admin/Home/Index.razor (page "/Admin/Dashboard")
Pages/Admin/.../...razor files

Now I get error 500. Not found
Pages/Admin/Home/Index.razor page "/" result into mismatch. page "/admin" results into using _Host.cshtml instead Admin.cshtml

EDIT: Figured it out.
Moved Pages/Admin/Admin.cshtml to Pages/_Admin.cshtml

Used
MapFallbackToPage("~/Admin/{*clientroutes:nonfile}", "/_Admin")

Pages/Admin/Home/Index.razor
@page "/admin"

Pages/Admin/_Host.cshtml for your entry point (set the right href in the base tag) and then you can put .razor pages inside Admin. Like Index.razor and so on.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FourLeafClover picture FourLeafClover  路  3Comments

guardrex picture guardrex  路  3Comments

markrendle picture markrendle  路  3Comments

ipinak picture ipinak  路  3Comments

farhadibehnam picture farhadibehnam  路  3Comments