Posts

Authorisation

Roles User can be added to one or more roles.  When the user is authenticated, these role memberships can be included in the authentication token. Claims Terminology to describe what the user has claims to (i.e. who they are and what privileges they have). JWT Tokens As well as containing the claims to be who they are, role memberships can be passed as claims so that the client application can expose / restrict areas of the application as that are applicable. Policies These are the rule sets that determine whether a service can be accessed (authorisation).  Roles and other logic can be used to determine a policy.

Bits and bobs

EF Global Filters These can be set up in OnModelCreating so that the default case is that the deleted items are not returned.  This can be overriden for specific queries using IgnoreQueryFilters. builder.Entity<Thing>().HasQueryFilter(p => p.Deleted); Displaying text over an Image For this we need to set the container div style to  position: relative and then the text to position: absolute.  Then set the bottom so that it appears in the corrrect place.

Publishing

Publishing to IIS Run >dotnet publish --configuration Release A . NET Core Hosting Bundle is required to publish to IIS. Download the bundle. TODO -  There seems to be a problem with the API connecting to the database and perfroming the login call.  I need to look further into this. Publishing to Azure Set up a Web App with Database in Azure. Correct the database connection string name Add firewall rule to access db from own machine. In VS Code, install the extension Azure App Services Enabled Hsts and Https Publish to Files from publish directory. Use developer exception page until happy.

Setting up for Deployment

Building Angular App into Kestrel wit the API Change output path in angular.json to "outputPath": "../DatingApi.API/wwwroot" Set up an ignore rule so we don't commit this folder. To expose the SPA we need to add the following two lines to our Startup.cs app.UseDefaultFiles(); app.UsesStaticFiles(); When refreshing, need to pass routing responsibility onto Angular.  Otherwise we get a page not found error. This is done by adding a new FallbackController which is an MVC controller (base class Controller rather than ControllerBase), that does the following: return PhysicalFile(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "index.html), "text/HTML"); And then in the startup endpoints, add: endpoints.MapFallbackToController("Index", "Fallback"); Creating a Production Build  - Ahead of Time (AOT) Using the --prod option on ng build does a lot of the things that you'd have to configur...

Troubleshooting notes

HTTP.Post gotcha on ASP.NET MVC Core API V3 If you don't provide all of the route parameters on the CreatedAtRoute an error is returned which suggests the routing could not find the controller.  What has actually happened is that the post has completed, but cannot return via the routing.

Pagination

On Server Side: Once you have an IQueryable<T> which has your stored command it it (i.e. the where and ordey by clauses) use .Skip and .Take to get the pages.  Pass in: pageNumber  pageSize Pass out: Items - so they can be displayed CurrentPage ItemsPerPage TotalItems - so this can be displayeded TotalPages - so this can provide other pages to load On Client Side Use PaginationModule from ngx-bootstrap.  This will provide navigation around the pages. When loading a new page, set only the TotalItems and TotalPages to prevent triggering a seconp page load.

Web API - Action Filters

Been looking at action filters which can be applied as declarative  attributes on a controller or even across the whole app.  This could be used for cross cutting concerns such as logging and auditing. [ServiceFilter(typeof(MyLogger))] Where MyLogger need to implement IAsyncActionFilter and have been registered as a service in StartUp