Sunday, October 31, 2021
Angular 12 select box with default value, required validator and state-city dependency
Angular 12 select box binding to an object list
In this sample the city field binds with CityList which is a list of objects consisting of id and names.
Required field validator is applied.
Angular 12 select box with a simple string list binding
Most Basic angular select box which binds to a list of strings. It has a "Choose" option and a required validator applied.
Sunday, October 24, 2021
frmabc = this.fb.group({
Basic Angular Reactive Form Validation with Validation messages
1. app.component.html
2. app.component.ts
NOTES :
1. maxLength validator put in ts file will not by itself restrict the input to max length. To restrict the input to maxlength, use the maxlength attribute in .html also, in addition to the one in .ts.
<input .... maxlength = "10" />
2. If you get "possible null value" error, do not forget to use the "?" operator.
Thursday, September 2, 2021
Wednesday, August 25, 2021
dev.to
dev.to
Good short no-nonsense useful articles
https://dev.to/palashmon/6-awesome-css-layout-generators-pbc
6 Awesome CSS Layout Generators
Web Development (3 Part Series)
1 Ultimate Cheatsheet Compilation
2 10 Awesome JavaScript Shorthands
3 6 Awesome CSS Layout Generators
https://dev.to/hb/10-fun-apis-to-use-for-your-next-project-2lco
10 Fun APIs to Use For Your Next Project
https://dev.to/hb/top-5-ides-code-editors-for-web-development-2mdo
Top 5 IDEs/Code Editors for Web Development
https://dev.to/hb/python-developer-roadmap-in-2021-2bmo
Python Developer Roadmap in 2021
https://dev.to/hb/30-machine-learning-ai-data-science-project-ideas-gf5
30 Machine Learning, AI, & Data Science Project Ideas
https://dev.to/hb/10-advanced-projects-to-build-in-2021-425o
10 Advanced Projects to Build in 2021
Friday, August 20, 2021
Resources
10 Resources for Learning LINQ
https://grantwinney.com/10-resources-for-learning-linq/
https://grantwinney.com/
https://docs.microsoft.com/en-us/dotnet/architecture/microservices/multi-container-microservice-net-applications/data-driven-crud-microservice
Creating a simple data-driven CRUD microservice
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-5.0
ASP.NET Core Middleware
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/startup?view=aspnetcore-5.0
App startup in ASP.NET Core
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/?view=aspnetcore-5.0&tabs=windows
ASP.NET Core fundamentals
https://docs.microsoft.com/en-us/aspnet/core/blazor/?view=aspnetcore-5.0
Introduction to ASP.NET Core Blazor
https://techcommunity.microsoft.com/t5/microsoft-learn-blog/how-to-stay-motivated-during-your-learning-journey/ba-p/1469345
How to stay motivated during your learning journey
Wednesday, August 11, 2021
Entity Tracking in Entity Framework
Tracking is the feature of EF used to track changes in entities.
If entities are changed, the changes are persisted to database during SaveChanges(), because those changes are tracked by EF.
Remember that Keyless entities are never tracked.
Any query that returns an entity type is a tracking query. By default any query returning entity is called a tracking query and it is tracked.
Even if a query anonymously returns an entity type, EF detects is and tracks the entity.
To disable tracking on an entity returning query, use AsNoTracking()
context.Blogs.AsNoTracking().ToList();
This behaviour can also be changed at context level:
context.ChangeTracker.QueryTrackingBehaviour = QueryTrackingBehaviour.NoTracking;
Identity Resolution: EF keeps track of tracked entities using the identity. It always maintains a single instance of tracked entities and returns the same instance when demanded, without hitting database. Thus when an entity is asked for, EF first checks whether entity with that identity already exists in context and returns the same if exists. This checking is done purely on the basis of identity property of the entity.
This feature is called Identity resolution.
Non-tracking queries are not tracked, hence identity resolution is not done for them. Every time a no-tracking query is called, it results in a database hit.
Now in EF5.0, we can have a non-tracking query with identity resolution. You need to use AsNoTrackingWithIdentityResolution() method for that.
This creates a separate stand-alone tracker for this query and tracks it. After the query is enumerated fully, this stand-alone tracker goes out of scope and is garbage-collected. The context is not aware of this stand-alone tracking.
What happens to tracking when the query contains a mix of tracked and keyless entities ?
From EF3.0 onwards, keyed entities in such mixed queries ARE tracked and keyless entities
are not tracked.
Prior to EF3.0, the entire query results were untracked.
https://www.softwareblogs.com/Home/Blog/how/DiffEF6andCore/entity-framework-6-entity-framework-core-difference-compare-examples
https://docs.microsoft.com/en-us/ef/efcore-and-ef6/
https://www.learnentityframeworkcore.com/
https://www.entityframeworktutorial.net/Types-of-Entities.aspx
https://chadgolden.com/blog/comparing-performance-of-ef6-to-ef-core-3
Thursday, August 5, 2021
Basic Client Authentication Using IdentityServer4 - The Client
Let us now create the client. Out client will be a web api project which exposes weatherforecast api.
1. Create a new asp .net core web api project:
2. Main changes will be in startup.cs and a minor change is required in the controller file.
We need to use JwtBearerDefaults structure in startup.cs. For that we need to install
IdentityServer4.AccessTokenValidation package. Let us install this using nuget:
3. In startup.cs, in the ConfigureServices method, add the following :
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddAuthentication(options => {
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(op =>
{
op.Authority = "https://localhost:44368";
op.Audience = "weatherapiresource";
});
}
This completes your modifications in startup.cs. The only remaining thing is to add [Authorize] attribute in controller.
5. Go to controllers\WeatherForecastController and add [Authorize] attribute before the [HttpGet] attribute of Get() method. You will need to reference Microsoft.AspNetCore.Authorization for it.
[Authorize]
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
6. Build and Run the project.
7. Notice that the project runs but gives an authorization error in the browser:
The same error is given in postman too:
8. This is because now the weatherforecast api requires a token to allow access to it.
So let us generate a token using POSTMAN by calling /connect/token endpoint and then pass it to get request.
To pass a token to get request in POSTMAN, open the "Authorization" tab of the request:
Then open the "Type" drop down and select "Bearer Token"
And resend the GET request by pressing the "Send" button.
9. Provided the token is not old and expired, you should now get the response of weatherforecast get api.
Basic Client Authentication Using Identity Server 4 - The Server
The aim of this tutorial is to use Identity Server 4 for client authentication. We will build two different VS projects, one will be server and other will be client. The server will host IdentityServer4 and do the task of authentication. The authentication will be based on client credentials, hence user , user id and password will not be required.
Building the Identity Server
1. Create a new asp.net core web application project (the screen shots pertain to Visual Studio 2019).
{"issuer":"https://localhost:44368","jwks_uri":"https://localhost:44368/.well-known/openid-configuration/jwks","authorization_endpoint":"https://localhost:44368/connect/authorize","token_endpoint":"https://localhost:44368/connect/token","userinfo_endpoint":"https://localhost:44368/connect/userinfo","end_session_endpoint":"https://localhost:44368/connect/endsession","check_session_iframe":"https://localhost:44368/connect/checksession","revocation_endpoint":"https://localhost:44368/connect/revocation","introspection_endpoint":"https://localhost:44368/connect/introspect","device_authorization_endpoint":"https://localhost:44368/connect/deviceauthorization","frontchannel_logout_supported":true,"frontchannel_logout_session_supported":true,"backchannel_logout_supported":true,"backchannel_logout_session_supported":true,"scopes_supported":["read","write","delete","allow_weather_api","offline_access"],"claims_supported":[],"grant_types_supported":["authorization_code","client_credentials","refresh_token","implicit","urn:ietf:params:oauth:grant-type:device_code"],"response_types_supported":["code","token","id_token","id_token token","code id_token","code token","code id_token token"],"response_modes_supported":["form_post","query","fragment"],"token_endpoint_auth_methods_supported":["client_secret_basic","client_secret_post"],"id_token_signing_alg_values_supported":["RS256"],"subject_types_supported":["public"],"code_challenge_methods_supported":["plain","S256"],"request_parameter_supported":true}
If opened in POSTMAN with a GET request, the output will look like
You can also get token by calling /connect/token endpoint{"issuer": "https://localhost:44368","jwks_uri": "https://localhost:44368/.well-known/openid-configuration/jwks","authorization_endpoint": "https://localhost:44368/connect/authorize","token_endpoint": "https://localhost:44368/connect/token","userinfo_endpoint": "https://localhost:44368/connect/userinfo","end_session_endpoint": "https://localhost:44368/connect/endsession","check_session_iframe": "https://localhost:44368/connect/checksession","revocation_endpoint": "https://localhost:44368/connect/revocation","introspection_endpoint": "https://localhost:44368/connect/introspect","device_authorization_endpoint": "https://localhost:44368/connect/deviceauthorization","frontchannel_logout_supported": true,"frontchannel_logout_session_supported": true,"backchannel_logout_supported": true,"backchannel_logout_session_supported": true,"scopes_supported": ["read","write","delete","allow_weather_api","offline_access"],"claims_supported": [],"grant_types_supported": ["authorization_code","client_credentials","refresh_token","implicit","urn:ietf:params:oauth:grant-type:device_code"],"response_types_supported": ["code","token","id_token","id_token token","code id_token","code token","code id_token token"],"response_modes_supported": ["form_post","query","fragment"],"token_endpoint_auth_methods_supported": ["client_secret_basic","client_secret_post"],"id_token_signing_alg_values_supported": ["RS256"],"subject_types_supported": ["public"],"code_challenge_methods_supported": ["plain","S256"],"request_parameter_supported": true}
How to check local and global angular versions
Use the command ng version (or ng v ) to find the version of Angular CLI in the current folder. Run it outside of the Angular project, to f...
-
Most of the google tutorials on keras do not show how to display a confusion matrix for the solution. A confusion matrix can throw a clear l...
-
This error means you have created the DbContext but not configured/added it to the project using either DI in startup.cs or by using DbCon...
-
CONCLUSION : 1. Normally, use following two when you do not want query compilation also to come into picture. CHECKPOINT DBCC DROPCLEA...