How to specify the view location in asp.net core mvc when using custom locations?

Great news… In ASP.NET Core 2 and up, you don’t need a custom ViewEngine or even ExpandViewLocations anymore. Using the OdeToCode.AddFeatureFolders Package This is the easiest way… K. Scott Allen has a nuget package for you at OdeToCode.AddFeatureFolders that is clean and includes optional support for areas. Github: https://github.com/OdeToCode/AddFeatureFolders Install the package, and it’s as … Read more

How to mock the new HttpClientFactory in .NET Core 2.1 using Moq

The HttpClientFactory is derived from IHttpClientFactory Interface So it is just a matter of creating a mock of the interface var mockFactory = new Mock<IHttpClientFactory>(); Depending on what you need the client for, you would then need to setup the mock to return a HttpClient for the test. This however requires an actual HttpClient. var … Read more

Should HttpClient instances created by HttpClientFactory be disposed?

Calling the Dispose method is not required but you can still call it if you need for some reasons. Proof: HttpClient and lifetime management Disposal of the client isn’t required. Disposal cancels outgoing requests and guarantees the given HttpClient instance can’t be used after calling Dispose. IHttpClientFactory tracks and disposes resources used by HttpClient instances. … Read more

What is the difference between UseStaticFiles, UseSpaStaticFiles, and UseSpa in ASP.NET Core 2.1?

Static files, such as HTML, CSS, images, and JavaScript, are assets an ASP.NET Core app serves directly to clients. Some configuration is required to enable serving of these files. UseStaticFiles – Serve files inside of web root (wwwroot folder) UseSpaStaticFiles – Serve static file like image, css, js in asset folder of angular app UseSpa … Read more

Identity in ASP.Net Core 2.1< - Customize AccountController

ASP.NET Core 2.1 introduced new feature called Razor class libraries that lets you build views and pages as part of reusable library. ASP.NET Core Identity was moved to such RCL. You can override it in your project: From Solution Explorer, right-click on the project > Add > New Scaffolded Item. From the left pane of … Read more

Setting the default value of a DateTime Property to DateTime.Now inside the System.ComponentModel Default Value Attrbute

You cannot do this with an attribute because they are just meta information generated at compile time. Just add code to the constructor to initialize the date if required, create a trigger and handle missing values in the database, or implement the getter in a way that it returns DateTime.Now if the backing field is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)