Enable secret storage:Type “dotnet user-secrets init” into Package Manager Console <UserSecretsId> can be found in .csproj file. Set a secret (Package Manager Console):dotnet user-secrets set “ApiKey” “test123” or to remove it:dotnet user-secrets remove “ApiKey” To check if exists:dotnet user-secrets listorManage secret through GUI -> right click on project -> Manage User Secrets -> it opensContinue reading “Secret storage in .NET”
Author Archives: Karol N
The term ‘dotnet-ef’ is not recognized – Entity Framework error
Quick post about fixing Entity Framework, probably common error when you want to use ef for the first time e.g. you installed Visual Studio on new pc, fresh os, new project etc. and want to make dotnet-ef migrations or database update. Error message:“dotnet-ef : The term ‘dotnet-ef’ is not recognized as the name of aContinue reading “The term ‘dotnet-ef’ is not recognized – Entity Framework error”
Scaffolding in .NET Core (generate API controllers – CRUD (or MVC controller with views in necessary)
Right click on ‘Controllers’ folder –> Add –> New Scaffolded Item… For api controller without views select ‘API Controller with actions, using Entity Framework’ and click ‘Add’.If MVC then choose ‘MVC Controller with views, using using Entity Framework’ On next view select your model (you need create model before generate code) and select data contextContinue reading “Scaffolding in .NET Core (generate API controllers – CRUD (or MVC controller with views in necessary)”
Background automation tasks in .NET Core – sample web application using Hangfire
It is the second post about Hangfire, but this time I am using Hangfire in web application. And there is link to previous post about Hanfire in console application:Background automation tasks in .NET – sample console application using Hangfire I will show a simple web application using Hangfire to automate tasks. First, create a new project:Continue reading “Background automation tasks in .NET Core – sample web application using Hangfire”
Background automation tasks in .NET Core – sample console application using Hangfire
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”
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]:
Git clone fatal: Authentication failed
I recently had a problem with git credentials on Windows and a message like “git clone fatal: Authentication failed for…” Git did not work because the old password was set. In order for git to work again, I had to change the password in Windows settings. To fix this, go to the following path: AndContinue reading “Git clone fatal: Authentication failed”