我在.net core 3.0中有一个项目,包括3个部分:api,共享和出色的应用程序。
我在共享项目中添加了几个模型,并添加了一个用户模型:
<?php
$file = "testfile.php"; // call the file
$f = fopen($file, 'rb'); // open the file
$found = false;
while ($line = fgets($f, 1000)) { // read every line of the file
if ($found) {
echo $line;
continue;
}
if (strpos($line, "css:") !== FALSE) { // if we found the word 'css:' we print everything after that
$found = true;
}
}
但是当我运行烈火机时,我得到了一个错误
[Table("user")]
public class User : IdentityUser<Guid>
{
[Required(ErrorMessage = "Firstname is required")]
[StringLength(32, ErrorMessage = "Firstname must be 32 charaters maximum")]
[Column("firstname")]
public string Firstname { get; set; }
[Required(ErrorMessage = "Lastname is required")]
[StringLength(32, ErrorMessage = "Lastname must be 32 charaters maximum")]
[Column("lastname")]
public string Lastname { get; set; }
[Required(ErrorMessage = "Thumbnail link is required")]
[StringLength(512, ErrorMessage = "Thumbnail link must be 512 charaters maximum")]
[Column("thumbnail_link")]
public string ThumbnailLink { get; set; }
[Column("birthday")]
public DateTime Birthday { get; set; }
[Required(ErrorMessage = "CreationDate is required")]
[Column("creation_date")]
public DateTime CreationDate { get; set; }
// [Required(ErrorMessage = "User role is required")]
// [Column("user_role")]
// public UserRole UserRole { get; set; }
[Required(ErrorMessage = "Is a banned user is required")]
[Column("is_banned")]
public IsBanned IsBanned { get; set; }
public ICollection<UserRole> UserRoles { get; set; }
public ICollection<UserProgression> UserProgressions { get; set; }
public ICollection<Playlist> Playlists { get; set; }
// public ICollection<Message> MessagesReceived { get; set; }
// public ICollection<Message> MessagesSended { get; set; }
public ICollection<Rating> Ratings { get; set; }
public ICollection<Course> Courses { get; set; }
public ICollection<SubscriptionHistory> SubscriptionHistories { get; set; }
}
因此,用户从IdentityUser继承:
PackageReference Include =“ Microsoft.AspNetCore.Identity.EntityFrameworkCore” Version =“ 2.2.0”
我发现blazor不支持带有实体框架的软件包。
那么我该如何实现身份?如何在服务器端和前端之间共享模型?我是一个初学者,很难找到有关该主题的一些信息。
欢迎各种帮助!
谢谢
答案 0 :(得分:2)
不幸的是,您无法与blazor应用程序共享IdentityUser模型。 Blazor客户端在.Net标准2.0上运行,您的身份资产在Asp.net核心上运行。您可以在asp.net核心端使用.net标准代码,但不能相反。
要解决此问题,请将您的IdentityUser模型移至服务器,并在共享项目中创建一个具有您要向下传递到客户端的属性的“传递模型”,然后从实际的AspNetUsers表行中复制每个属性。无论如何,您想完全控制哪些用户可以看到AspNetUsers表。希望这可以帮助!