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

.NET Core MVC Page Not Refreshing After Changes

In ASP.NET Core 3.0 and higher, RazorViewEngineOptions.AllowRecompilingViewsOnFileChange is not available. Surprised that refreshing a view while the app is running did not work, I discovered the following solution: Add Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package to the project Add the following in Startup.cs: services.AddControllersWithViews().AddRazorRuntimeCompilation(); Here’s the full explanation for the curious.

How to configure ASP.net Core server routing for multiple SPAs hosted with SpaServices

Thanks to SteveSandersonMS and chris5287 over on Github for pointing me towards the solution on this. IApplicationBuilder.Map can segregate paths into different areas of concern. If you wrap a call to app.UseSpa in a call to app.Map, the SPA will be handled only for the path specified by the Map call. The app.UseSpa call ends … Read more

why remove-migration run my app?

Update for ASP.NET Core 2.1 In ASP.NET Core 2.1 the methods changed slightly. The general method is similar to the 2.0, just the methods name and return types have been changed. public static void Main(string[] args) { CreateWebHostBuilder(args) .Build() .Migrate(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) { return new WebHostBuilder() …; // Do not call … Read more