asp.net-core
.NET Core vs ASP.NET Core
Update 2020: Do note that ASP.NET Core 3 and higher now depend on .NET Core and can no longer be used on .NET Framework. The below description is for ASP.NET Core 1.x-2.x; the layer separation still holds true for ASP.NET Core 3.0 but the ASP.NET Core layer can no longer be used on top of … Read more
OData Support in ASP.net core
Edit: now available at https://www.nuget.org/packages/Microsoft.OData.Core/ It’s in the road map, OData Lib has released 7.0.0 which is a breaking change release, OData/WebAPI will release 6.0.0 based on this, after the release, we will consider to support ASP.NET Core. Relative issue: https://github.com/OData/WebApi/issues/772
AddDbContext or AddDbContextPool
The answer is here (under “DbContext pooling”): https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-2.0#dbcontext-pooling DbContext is not thread-safe. So you cannot reuse the same DbContext object for multiple queries at the same time (weird things happen). The usual solution for this has been to just create a new DbContext object each time you need one. That’s what AddDbContext does. However, there … Read more
Is it possible to self-host an ASP.NET Core Application without IIS?
Is it possible to self-host an ASP.NET Core Application without IIS? Yes. In fact, all ASP.NET Core applications are self-hosted. Even in production, IIS/Nginx/Apache are a reverse proxy for the self-hosted application. In a reasonably standard Program.cs class, you can see the self-hosting. The IISIntegration is optional – it’s only necessary if you want to … Read more
How to update the model when using database first approach
You can re-scaffold the model by running the command that you originally ran with the -Force option added. That will result in the contents of the specified folder being over-written. Using the Package Manager Console example from the EF Core docs, the revised command becomes: Scaffold-DbContext “Server=(localdb)\v11.0;Database=Blogging;Trusted_Connection=True;” Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Force Alternatively, if you are … Read more
Google JWT Authentication with AspNet Core 2.0
Posting my ultimate approach for posterity. As Tratcher pointed out, the AddGoogle middleware is not actually for a JWT authentication flow. After doing more research, I realized that what I ultimately wanted is what is described here: https://developers.google.com/identity/sign-in/web/backend-auth So my next problems were I could not rely on the standard dotnet core Jwt auth middleware … Read more
dotnet publish doesn´t publish correct appsettings.{env.EnvironmentName}.json
Update: For current (new) .csproj format the CopyToPublishDirectory attribute should be used. It determines whether to copy the file to the publish directory and can have one of the following value: Always, PreserveNewest Never So add next section into your .csproj: <ItemGroup> <None Include=”appsettings.Production.json” CopyToPublishDirectory=”Always” /> </ItemGroup> Look into @nover answer and SO Exclude or … Read more
Export html to pdf in ASP.NET Core
You can use jsreport .net sdk if you are in .net core 2.0 also without more complex node services. This includes among other features filters to convert your existing razor views into pdf. From the docs: 1. Install nugets jsreport.Binary, jsreport.Local and jsreport.AspNetCore 2. In you Startup.cs configure it as the following public void ConfigureServices(IServiceCollection … 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