I would like to append two different CSS files based on session state user_id in an ASP.NET Core Blazor project (Server-side Blazor).
I have two css file for user 1 & 2
For example:
- If its user 1 css site1 should be appended on _Host.cshtml.
- If its user 2 css site2 should be appended on _Host.cshtml.
And the user_id= 1 and Userid = 2 in P
1.var user_id = await storage.GetAsync<int>("user");
this how the User_id is taken using await async. Now the requirement is to take the user_id on _host.cshtml so that
On _Host.cshtml
@if(user_id ==1)
{
<link href="css/site1.css" rel="stylesheet" />
}
else if (user_id ==2)
{
<link href="css/site2.css" rel="stylesheet" />
}
Now iam unabe to use function (await storage.GetAsync(User_id);) on _host.cshtml
This is how a _Host.cshtml page looks
@page
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta charset="utf-8" />
<title>ProjectName</title>
<link rel="icon" type="image/png" sizes="32x32" href="images/tenantA/favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="images/tenantA/favicons/favicon-16x16.png">
</head>
<body class="something">
<app>
@(await Html.RenderComponentAsync<App>(RenderMode.Server))
</app>
<script src="_framework/blazor.server.js"></script>
<link href="css/tenantA/site.css" rel="stylesheet" />
</body>
</html>
Now i need to get user_id on cshtml which is await call
@page "/"
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@if(User_id =="1")
{
<link href="css/site1.css" rel="stylesheet" />
return;
}
<!DOCTYPE html>
<html lang="en">
<head>
....
...
..
.
This one is currently stopping my project . Please help me as soon as possible