我已经将项目从.NET Core 1.1更改为2.0版本,但是当它尝试添加商店时,我从Identity中收到错误:
services.AddIdentity<ApplicationUser, IdentityRole<long>>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)
抛出的错误是:
只能使用派生自IdentityRole的角色调用AddEntityFrameworkStores
这些是我的课程:
public class ApplicationUser : IdentityUser<long>
{
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityRole<long>, long>
{
public ApplicationDbContext(DbContextOptions options) : base(options) {
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮帮我吗?
asp.net-identity asp.net-core-mvc .net-core asp.net-core-2.0
我正在尝试从我的Web API中的控制器之外的Context中获取当前用户.我正在使用OpenIddict对用户进行身份验证,因此授权是由令牌进行的.
我在我的Startup.cs中注册了HttpContextAcessor作为单例:
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
Run Code Online (Sandbox Code Playgroud)
之后,我在我的集线器中注入了HttpContexrAcessor,如下所示:
public class NotificationHub : Hub
{
private IHttpContextAccessor _contextAccessor;
private HttpContext _context { get { return _contextAccessor.HttpContext; } }
public NotificationHub(IHttpContextAccessor contextAccessor)
{
_contextAccessor = contextAccessor;
}
public async Task JoinGroup()
{
Groups.Add(Context.ConnectionId, $"notification_{_context.User.Identity.Name}");
}
public void Send(JsonResult notification)
{
Clients.Client(Context.ConnectionId).sendNotification(notification);
}
}
Run Code Online (Sandbox Code Playgroud)
问题是_context.User.Identity.Name始终为null.
有办法做到这一点吗?
asp.net-mvc asp.net-core-mvc .net-core asp.net-core asp.net-core-webapi
我有一个大约4个月的项目,突然aurelia的CLI命令无效.
当我尝试执行au run --watch时,我收到一条消息,其中包含在路径下创建新项目的选项.
我已经尝试卸载并重新安装aurelia CLI,但这不起作用.
我做的最后一件事是执行git clean -xdf
我认为这可能是我项目的一部分.有人可以帮帮我吗?
回答
经过一番尝试,我解决了这个问题:
1)我重新安装Git和Node;
2)我删除了\AppData\Roaming\npm-cache路径下的所有文件;
3)我检查了Git和Node是否在环境变量的PATH中;
4)我运行npm install命令;
框架:.NET Core 2.1
我正在为 Serilog 使用 Elasticsearch 配置,如下面的代码所述:
启动文件
Log.Logger = new LoggerConfiguration().Enrich.FromLogContext()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(Configuration.GetSection("ElasticSearchURL").Value))
{
AutoRegisterTemplate = true,
MinimumLogEventLevel = Serilog.Events.LogEventLevel.Error
}).CreateLogger();
services.AddSingleton(Log.Logger);
Run Code Online (Sandbox Code Playgroud)
是否可以在运行时更改注入的 Logger 实例的日志级别?
private readonly ILogger<EmailService> _logger;
public EmailService(ILogger<EmailService> logger)
{
_logger = logger;
}
public async Task<Result> Send(Email email)
{
// CHANGE LOG LEVEL TO LOGINFORMATION HERE
_logger.LogInformation("MESSAGE");
}
Run Code Online (Sandbox Code Playgroud)