asp.net-core-2.1

ASP.NET Core cannot find cshtml file by path using RazorViewEngine

拟墨画扇 提交于 2019-12-11 04:59:58
问题 I want to find my cshtml file in my ASP.NET Core 2.1 Web API project. To do it, I'm using this code: var httpContext = new DefaultHttpContext { RequestServices = this.serviceProvider }; var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); var viewResult = this.razorViewEngine.FindView( actionContext, "~/PdfTemplate/ProjectRaport.cshtml", false); The file is here: But from code above, the View (that is ~/PdfTemplate/ProjectRaport.cshtml ) is null. How to

Value Object as Invalid Object in asp.net core 2.1

谁都会走 提交于 2019-12-11 03:49:26
问题 I have been using value object in asp.net core 2.0 project, which was running properly on that project. I updated the project to 2.1 and it is giving me an error as Invalid object name 'EntityAdress'. Entity: public class Company : AuditableEntity<long> { public int SalesRepId { get; set; } public string Name { get; set; } public int StatusId { get; set; } public EntityAdress Addresses { get; set; } public string BillingAddress { get; set; } } public class EntityAdress : ValueObject { private

Asp.Net Core 2.1 ApiController does not automatically validate model under unit test

有些话、适合烂在心里 提交于 2019-12-11 02:35:27
问题 I am using xUnit to unit test an ASP.NET Core 2.1 controller method that returns an ActionResult<T> . The controller class is decorated with the [ApiController] attribute so that the method, when running live, performs model validation automatically. However, the controller method does not automatically fire model validation in my unit test, and I can't figure out why. Here is my Unit Test . [Fact] public async Task post_returns_400_when_model_is_invalid() { // arrange var

How to generate the appsettings.<EnvironmentName>.json file?

匆匆过客 提交于 2019-12-10 22:38:01
问题 I have an asp.net core 2 web api which will be deployed across the following environments: INT, QA, STAGE, PRODUCTION environments. Based on the above, I need to have appsettings.<EnvironmentName>.json file for each environment. From the link : https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-2.1 , I see that In case of local development environment, the Environment Variable called ASPNETCORE_ENVIRONMENT is set to Development. In case of the deployment

Capture Session timeout on Server side in asp.net core 2.1

北战南征 提交于 2019-12-10 22:25:36
问题 I need to do something on Session End Event. How can I access this event? anything similar to this event maybe timeout? 回答1: The only way to handle this in ASP.NET Core - on page load on client side (in JS code) to schedule the timer for session timeout and warn the user when it's close to expire. If user responds - ping server side (to refresh the session), or redirect th euser to logout page is not. Your session timeout can be configured in Startup class. So you need to pass the same value

How to set Steeltoe Dynamic Logging works with 3rd party loggers as Serilog?

我怕爱的太早我们不能终老 提交于 2019-12-10 19:00:49
问题 I have ASP.NET Core 2.1 app in Pivotal Cloud Foundry where we want to be able to configure logging levels on fly. As logger provider we are using Serilog. Is it possible that Steeltoe Dynamic Logging works properly with 3rd party loggers and how? Here is what I tried: In Program.cs: public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseCloudFoundryHosting() .ConfigureLogging((builderContext, loggingBuilder) => { loggingBuilder

warning EF1000. What the best way to write parameters in “IN” statement?

二次信任 提交于 2019-12-10 18:59:33
问题 EF Core 2.1 throws warnings about SQL injection. There is my code snippet where it happens var query = await _ctx.Set<TABLE>() .FromSql("Select * from TABLE where Artikelnummer IN (" + string.Join(',', artNum) + ")") .AsNoTracking() .Select(z => new { z.Artikelnummer, z.Property }).ToArrayAsync(); where artNum (stands for Artikel Numbers) is array of int numbers, like [1,22,34 etc.]. I can't pass artNum as parameters in FromSql, because there will be single quotes and SQL throws an exception.

Load assembly in Startup.cs .net core 2.1

这一生的挚爱 提交于 2019-12-10 18:38:01
问题 i have nugget packages in a folder called nuqkgs and on project start up i want to load these packages(there dll's) into the project to use at run time. i use the following code to load them, and when i debug i can see the info and that the dll's are found and opened, however when they should be used i get the error that the dll can not be found, and i can see that the solution try's to look for them in the bin folder(they are located solution/nuqkgs/) i do NOT want to register the packages

Authenticate a .NET Core 2.1 SignalR console client to a web app that uses “Identity as UI”

那年仲夏 提交于 2019-12-10 18:18:41
问题 Using .NET Core 2.1 & VS2017 preview 2 I created a simple web server with "Identity as UI" as explained here and then added a SignalR chat following this. In particular I have: app.UseAuthentication(); app.UseSignalR((options) => { options.MapHub<MyHub>("/hubs/myhub"); }); .. [Authorize] public class MyHub : Hub .. "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:5000", "sslPort": 0 I start the debugger which

Background task of writing to the database by timer

流过昼夜 提交于 2019-12-10 17:29:08
问题 How to write to the database on a timer in the background. For example, check mail and add new letters to the database. In the example, I simplified the code just before writing to the database. The class names from the example in Microsoft. The recording class itself: namespace EmailNews.Services { internal interface IScopedProcessingService { void DoWork(); } internal class ScopedProcessingService : IScopedProcessingService { private readonly ApplicationDbContext _context; public