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

Remove “Server” header from ASP.NET Core 2.1 application

This solution works on IIS 10+ version and allows to remove x-powered-by and server headers in server response. In IIS 10 a new attribute was added: removeServerHeader. We need to create web.config file in asp.net core application with following content: <?xml version=”1.0″ encoding=”utf-8″?> <configuration> <system.webServer> <security> <requestFiltering removeServerHeader=”true” /> </security> <httpProtocol> <customHeaders> <remove name=”X-Powered-By” /> … Read more

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

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

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

techhipbettruvabetnorabahisbahis forumu