我在 mac 机器上使用 asp.net 核心,我试图为我的 asp.net mvc web 应用程序创建一个自定义的 ApplicationUser,它与基本 IdentityUser 一起工作得非常好。
尽管遵循 Microsoft 的本指南:
我面临这个错误:
{"error":"没有注册'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]'类型的服务。"}
以下是我的代码片段:
启动文件
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// [...]
services.AddDbContext<ApplicationDbContext>(
options => options.UseSqlServer(identityDbContextConnection));
// Relevant part: influences the error
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc(config =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
config.Filters.Add(new AuthorizeFilter(policy));
});
}
Run Code Online (Sandbox Code Playgroud)
应用程序用户.cs
// Add profile data for application users by adding properties to the ApplicationUser class
public class ApplicationUser : IdentityUser
{
[Required] …Run Code Online (Sandbox Code Playgroud) 我正在处理一个不断在控制台上抛出此错误的存储库:
Uncaught TypeError: this.getExtraNgModuleProviders is not a function.
这些项目在“ng serve”上编译得很好,但它在控制台上显示一个空白页面和那个错误。我尝试了很多事情,但我找不到出路。
我试过卸载和安装@angular/compiler,但没有用。问题似乎是 JitCompiler 没有找到this.getExtraNgModuleProviders
我认为this.getExtraNgModuleProvidersJitCompiler 中的函数应该this._getExtraNgModuleProviders在 compiler.js 上。因为它周围的所有功能似乎都包含下划线。
更新:
我不认为函数名称与它有任何关系,因为其他开发人员可以很好地运行该项目,并且他们拥有相同的 Jit compiler.js 文件。供参考:当我单击控制台上的错误时,这是我需要的地方
function JitCompiler(_metadataResolver, _templateParser, _styleCompiler, _viewCompiler, _ngModuleCompiler, _summaryResolver, _reflector, _compilerConfig, _console, getExtraNgModuleProviders) {
this._metadataResolver = _metadataResolver;
this._templateParser = _templateParser;
this._styleCompiler = _styleCompiler;
this._viewCompiler = _viewCompiler;
this._ngModuleCompiler = _ngModuleCompiler;
this._summaryResolver = _summaryResolver;
this._reflector = _reflector;
this._compilerConfig = _compilerConfig;
this._console = _console;
this.getExtraNgModuleProviders = getExtraNgModuleProviders;//<- error is pointed here
this._compiledTemplateCache = new Map();
this._compiledHostTemplateCache = …Run Code Online (Sandbox Code Playgroud)