asp.net-core-2.1

How to set ShutdownTimeout using HostBuilder Generic Host ref StopAsync OperationCanceledException

你说的曾经没有我的故事 提交于 2019-12-10 10:47:28
问题 Looking into the source code, the default Timeout for StopAsync is 5 seconds. WebHostBuilder provides an extension method UseShutdownTimeout for easy setting. But no such equivalent exists for HostBuilder . I know I'm probably abusing the intent of HostBuilder by wanting more than 5 second timeout, but it's a nice framework for managing a collection of interdependent jobs. I'd really appreciate some guidance on how to do with HostBuilder what UseShutdownTimeout does for WebHostBuilder whilst

.net core get user in ValidationAttribute

白昼怎懂夜的黑 提交于 2019-12-10 10:43:33
问题 I am trying to access the current user (i.e. ClaimsPrincipal from identity) in a custom ValidationAttribute, and I haven't figured out how I could do that. public class UniqueTitleValidator : ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext) { // var user = ? } } I know that I could access the user from a HttpContext (but I don't know how to get to the latter). The main problem is that I don't have access to the User. When I

Entity Framework Core Auto Generated guid

余生颓废 提交于 2019-12-10 09:33:44
问题 Can some One guide me I want primeryKey of a table as guid having db generated value on insert. [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } but it's giving error The seed entity for entity type 'User' cannot be added because there was no value provided for the required property 'Id'. Here is my actual model classes and DbContxt class: public class BaseModel { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; }

More than one DbContext named 'NewProject.Models.DbContext' was found Specify which one to use by providing its fully qualified name using exact case

可紊 提交于 2019-12-10 04:29:07
问题 I was developing a Web-App with Asp.Net Core 2.1 . After I added the new identity with scaffolder it generated me these codes: Code generated in IdentityStartup.cs [assembly:HostingStartup(typeof(ShareAndCare.Areas.Identity.IdentityHostingStartup))] namespace ShareAndCare.Areas.Identity { public class IdentityHostingStartup : IHostingStartup { public void Configure(IWebHostBuilder builder) { builder.ConfigureServices((context, services) => { services.AddDbContext<ShareAndCareContext>(options

Logging using AOP in .NET Core 2.1

孤者浪人 提交于 2019-12-09 07:14:30
问题 I want to implement AOP for the logging in my .NET Core 2.1 solution. I've never used it before and I've been looking online and cant seem to see any examples of people using it with Core 2. Does anyone know how i would go about this? For example what packages to use for AOP and have any example code to get me started? Im using the built in DI with .net core so i dont need to worry about that part. 回答1: Microsoft DI does not offer advances scenarios such as interceptor or decorators(there is

Asp Net Core 2.1 not listed in Visual Studio 2017 target framework

﹥>﹥吖頭↗ 提交于 2019-12-08 18:27:44
问题 I've installed the new AspNet Core 2.1 SDK - which is now official - but it's still not listed in Visual Studio 2017 target framework, oin both existing projects and new projects: As suggested in similar topics I've tried with: Installing both x64 and x32 versions of the SDK Installing the runtime separately Manually adding the installation path of the SDK to the environment variable PATH Manually updating an existing project (not worked because it wasn't able to find the 2.1 SDK) Restarting

.NET Core X509Certificate2 usage (under Windows/IIS, Docker, Linux)

╄→гoц情女王★ 提交于 2019-12-08 17:01:45
问题 I am really trying a long time to use certificates in .NET Core API. Basically where I need to use them is in a .NET Core web api running on IIS and docker. Certificates I need to use are for: Microsoft.AspNetCore.DataProtection public void ConfigureServices(IServiceCollection services) { services.AddDataProtection() .PersistKeysToFileSystem(new DirectoryInfo(dataProtectionKeystorePath)) .ProtectKeysWithCertificate ( new X509Certificate2(dataProtectionCertificatePath,

Asp.net Core Email confirmation sometimes says InvalidToken

江枫思渺然 提交于 2019-12-08 14:50:43
问题 I am using asp.net core identity 2.1 and i am having a random issue with email confirmation, which while email confirmation sometimes says result.Error = InvalidToken . The token is also not expired. Note: We are using multiple servers , and we have also stored our keys in one place so that all the servers use the same keys. Code snippet for email confirmation. Email Confirmation var confCode = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Action(

Can't install node in docker image microsoft/dotnet:2.1-sdk for windows architecture

老子叫甜甜 提交于 2019-12-08 06:32:11
问题 I asked this question originally at: https://github.com/aspnet/aspnet-docker/issues/349 as a part of the deprecation announcement, and I am hoping the SO community may have a good answer for this: I am trying to use the windows side for a SPA build using the microsoft/dotnet:2.1-sdk . I know, I may be the only one trying to stay on the windows side for an ASP.NET Core Application, but our swarm initially will only have windows servers running in the native OS mode and not Hyper-V mode. As a

How to inject services in a controller inside a reusable Razor Class Library

六眼飞鱼酱① 提交于 2019-12-08 04:25:56
问题 I am using a Razor Class Library for making a reusable complex View (which includes its controller and several View Components) that can be used across several ASP.NET Core MVC projects. The problem is that the controller use dependency injection (a custom service called "GatewayProxy" and string localization). What is the correct way to inject services into a controller inside a RCL? Here is the structure of my RCL: Here is the exception: 回答1: You mentioned how you fixed this by adding the