I am using ASP.NET Core & Identity 3.
When I log in I read the current select user's UI template and in my _Layout.cshml
file I load the css
based off this template.
The user can change his theme and I store it in a session variable via the controller
public IActionResult ChangeTheme(int id, string returnUrl)
{
HttpContext.Session.SetInt32("Template", (id));
return Redirect(returnUrl);
}
Instead of querying the database with every cshtml
load I put the Template in a Session variable and in my Layout.cshtml
I render a different css depending on the template
switch (template)
{
case (int)TemplateEnum.Template2:
<text>
<link rel="stylesheet" href="~/css/template1.css" />
</text>
break;
case (int)TemplateEnum.Template2:
<text>
<link rel="stylesheet" href="~/css/template2.css" />
</text>
break;
{
I'm wondering what happens if the session expires.
Taking into account I access the value in my
_Layout.cshtml
is there anyway to catch it if it becomes null and immediately load it from the db before a new page is rendered.Since I use Identity 3, is Claims maybe a better option? I haven't used it before. What would the code be for my example above
Another option that is better for my scenario?