Lamp
Lamp
CC#
Created by Lamp on 3/7/2024 in #help
ASP.NET Identity Login Error
When trying to sign in using SignInManager, I get a SqlException: Invalid column name 'UserId1'. Why is there an extra user column being added to the query? My extended identity classes are listed below.
var result = await _signInManager.PasswordSignInAsync(
user,
Input.Password,
Input.RememberMe,
lockoutOnFailure: false
);
var result = await _signInManager.PasswordSignInAsync(
user,
Input.Password,
Input.RememberMe,
lockoutOnFailure: false
);
public class ApplicationUser : IdentityUser
{
[Required(ErrorMessage = "First name is required")]
[Display(Name = "First Name")]
[MaxLength(50)]
public string FirstName { get; set; }

[Required(ErrorMessage = "Last name is required")]
[Display(Name = "Last Name")]
[MaxLength(50)]
public string LastName { get; set; }

public virtual ICollection<ApplicationUserClaim> Claims { get; set; }

public virtual ICollection<IdentityUserLogin<string>> Logins { get; set; }

public virtual ICollection<IdentityUserToken<string>> Tokens { get; set; }
}

public class ApplicationRole : IdentityRole
{
}

public class ApplicationUserRole : IdentityUserRole<string>
{
public bool IsReadOnly { get; set; }

public string ProgramId { get; set; }

public bool IsDefault { get; set; }

public virtual TestProgram Program { get; set; }
}

public class ApplicationRoleClaim : IdentityRoleClaim<string>
{
public virtual ApplicationRole Role { get; set; }
}

public class ApplicationUserClaim : IdentityUserClaim<string>
{
public virtual ApplicationUser User { get; set; }
}

public partial class ApplicationDbContext : IdentityDbContext<
ApplicationUser, ApplicationRole, string,
ApplicationUserClaim, ApplicationUserRole, IdentityUserLogin<string>,
ApplicationRoleClaim, IdentityUserToken<string>>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}

/// DbSets

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
public class ApplicationUser : IdentityUser
{
[Required(ErrorMessage = "First name is required")]
[Display(Name = "First Name")]
[MaxLength(50)]
public string FirstName { get; set; }

[Required(ErrorMessage = "Last name is required")]
[Display(Name = "Last Name")]
[MaxLength(50)]
public string LastName { get; set; }

public virtual ICollection<ApplicationUserClaim> Claims { get; set; }

public virtual ICollection<IdentityUserLogin<string>> Logins { get; set; }

public virtual ICollection<IdentityUserToken<string>> Tokens { get; set; }
}

public class ApplicationRole : IdentityRole
{
}

public class ApplicationUserRole : IdentityUserRole<string>
{
public bool IsReadOnly { get; set; }

public string ProgramId { get; set; }

public bool IsDefault { get; set; }

public virtual TestProgram Program { get; set; }
}

public class ApplicationRoleClaim : IdentityRoleClaim<string>
{
public virtual ApplicationRole Role { get; set; }
}

public class ApplicationUserClaim : IdentityUserClaim<string>
{
public virtual ApplicationUser User { get; set; }
}

public partial class ApplicationDbContext : IdentityDbContext<
ApplicationUser, ApplicationRole, string,
ApplicationUserClaim, ApplicationUserRole, IdentityUserLogin<string>,
ApplicationRoleClaim, IdentityUserToken<string>>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}

/// DbSets

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
179 replies
CC#
Created by Lamp on 3/5/2024 in #help
Shadow Prop Error with IdentityDbContext
This is my IdentityDbContext: public class ApplicationUser : IdentityUser { [Required(ErrorMessage = "First name is required")] [Display(Name = "First Name")] [MaxLength(50)] public string FirstName { get; set; } [Required(ErrorMessage = "Last name is required")] [Display(Name = "Last Name")] [MaxLength(50)] public string LastName { get; set; } public virtual ICollection<ApplicationUserClaim> Claims { get; set; } public virtual ICollection<IdentityUserLogin<string>> Logins { get; set; } public virtual ICollection<IdentityUserToken<string>> Tokens { get; set; } } public class ApplicationRole : IdentityRole { } public class ApplicationUserRole : IdentityUserRole<string> { public bool IsReadOnly { get; set; } public string ProgramId { get; set; } public bool IsDefault { get; set; } public virtual TestProgram Program { get; set; } } public class ApplicationRoleClaim : IdentityRoleClaim<string> { public virtual ApplicationRole Role { get; set; } } public class ApplicationUserClaim : IdentityUserClaim<string> { public virtual ApplicationUser User { get; set; } } I keep getting weird errors, especially when using the Login page, where it includes extra userid columns in the query, e.g. "UserId1". Any idea how to fix? I've been researching for quite a while and would love a hint in the right direction. Please let me know any additional information that would be needed. Also, I do have "base.OnModelCreating(modelBuilder);" in my dbcontext OnModelCreating method.
1 replies
CC#
Created by Lamp on 2/7/2024 in #help
.NET 8 - Blazor Server with Per page/component interactivity vs Global
What's the difference? I don't understand the documentation.
19 replies
CC#
Created by Lamp on 2/7/2024 in #help
MudBlazor darkmode toggle not working
I just want to check system preferences on load for the theme, but also allow the user to change from dark to light mode whenever they want. The toggle just doesn't work. I click on it and nothing happens. @inherits LayoutComponentBase <MudThemeProvider @ref="@provider" @bind-IsDarkMode="@useDarkMode" /> <MudDialogProvider /> <MudSnackbarProvider /> <MudLayout> <MudAppBar Elevation="1">
<MudText Typo="Typo.h5" Class="ml-3">[Text Here]</MudText> <MudSpacer/> <MudSwitch @bind-Value="useDarkMode" Color="Color.Primary" Class="ma-4" T="bool" Label="Toggle Light/Dark Mode" /> <MudIconButton Icon="@Icons.Material.Filled.MoreVert" Color="Color.Inherit" Edge="Edge.End"/> </MudAppBar> <MudMainContent> @Body </MudMainContent> </MudLayout> @code { private bool useDarkMode; private MudThemeProvider provider; protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { useDarkMode = await provider.GetSystemPreference(); await provider.WatchSystemPreference(OnSystemPreferenceChanged); StateHasChanged(); } } private async Task OnSystemPreferenceChanged(bool newValue) { useDarkMode = newValue; StateHasChanged(); } }
18 replies