I will show a simple console application using Hangfire to automate tasks. First, create a new project: Console App (.NET Core). In my case netcoreapp3.1: Install Hangfire – add packages:Hangfire.CoreHangfire.SqlServer Copy the following code to the Main method: We also need to add namespaces: And the last step, create a database. Go to SSMS andContinue reading “Background automation tasks in .NET Core – sample console application using Hangfire”
Category Archives: .NET
AutoMapper – map one list to another
Create a mapping from list to list: So e.g: Where ‘cars’ is of the List type and of course before it, we need to add a map to AutoMapper config with the .CreateMap and .ForMember methods for the appropriate properties if needed.
FileResult in controller and returning NotFound
Return NotFound() in FileResult. Just change return type to ActionResult, because FileResult inherits from ActionResult. And then it is possible to return NotFound() e.g. when object equals null. So FileResult -> ActionResult, something like this:
Passing argument to Main method in Visual Studio
To pass arguments to Main method in Visual Studio we can go to the following path: We can write down new arguments there: And we can use our added arguments with args[] and the appropriate index e.g. args[0], args[1]:
How to stop void method (return in void method)
This is quick blog post about stopping executing void method. So, how to stop executing void return type method? We just need to use ‘return’ statement itself, for example: If we pass 0 as first argument then we won’t get print from next line.
Problem with correctly display Razor Pages with IdentityServer
I had problem with login/registration pages UI looks. And problem was with lacking of app.UseStaticFiles(); in Configure method of Startup class. UI before changes: So to solve these errors we need add “app.UseStaticFiles();” in Startup.cs. Changes in Startup.cs, Configure method: UI after changes: Now it looks a little better 🙂
IdentityServer configuration to use it with SPA that is not hosted with IdentityServer
IdentityServer settings configuration to use it with SPA that is not hosted with IdentityServer. For example, we have client app on http://localhost:4200 and backend app on https://localhost:5001. To allow working it, we need to set/change “Profile” to “SPA”. Additional we can configure “RedirectUri” and “LogoutUri”. Backend side (.NET Core 3.1).Code snippet of appsettings.json:
OperationalStoreOptions in xUnit
I had little issue with creating IOptions<> to use it with xUnit, so below is solution: var operationalStoreOptions = Options.Create(new OperationalStoreOptions()); Example usingConstructor in my class with DbContext looks like: Corresponding lines of code in my xUnit test class: