- Kudvenkat (the teacher)
- ASP.NET Core MVC For Beginners
- Introduction
- WEB SERVER HOSTING
- WEB APP CONFIGURATION
- MVC
- DEPENDENCY INJECTION
- PAGE VIEWS
- ROUTING
- TAG HELPERS
- MODELS
- SERVER SIDE VALIDATION
- ENTITY FRAMEWORK CORE
- Error Handling
- Logging
- ASP.NET Core Identity - Authentication & Authorization
- PASSWORD/TOKENS/ENCRYPTION/DECRYPTION MANAGEMENT
- CLIENT SIDE VALIDATION
- MSSQL SERVER
- Other
- C# Programming Language
- Other Topics
- NOTES
- https://www.youtube.com/@Csharp-video-tutorialsBlogspot
- How to become a Full-Stack Web Developer: https://youtu.be/RiKcSDbGVXw
- https://www.pragimtech.com/
- Learn how to build applications that are:
- Real world enterprise class.
- Data driven web applications.
- +20hs videos, 124 videos.
- This project is compatible with NET Core 8.0
- Source code for .NET Core app 2.2: https://drive.google.com/drive/folders/1GM6gYJYQcMjf1WdGvK0z0wp1t69dESyW
- Creating asp net core web application 📺 - Part 01 📑
- The course is for NET Core 2.2
- Setting up machine for ASP.NET Core Development 📺 - Part 02 📑
- Creating a ASP.NET Core Web Application 📺 - Part 03 📑
- Project file 📺 - Part 04 📑
- Main method 📺 - Part 05 📑
- InProcess Hosting 📺 - Part 06 📑
WebApplication.CreateBuilder(args);
- One web server: Kestrel or IIS Express- IIS worker process (w3wp.exe or iisexpress.exe)
- No proxy request penalties
- OutOfProcess Hosting (default) 📺 - Part 07 📑
dotnet.exe
process- Internal server: Kestrel
- External web server (or reverse proxy server): IIS (Express), Nginx or Apache
launchsettings.json
file 📺 - Part 08 📑IConfiguration
service:- Middlewares introduction 📺 - Part 10 📑
- Static files and default files 📺 - Part 12 📑
- Developer Exception Page 📺 - Part 13 📑
- Development environments: Environment variables from OS 📺 - Part 14 📑
- Development, Staging, Production
ASPNETCORE_ENVIRONMENT
for selecting the run environment.
- Using
libman
📺 - Part 34 📑- Use LibMan with ASP.NET Core in Visual Studio 📑
- MVC Design 📺 - Part 15 📑
- MVC Model = Model class and class repository
- NET Core MVC project set up (2.2 version) 📺 - Part 16 📑
- MVC Implementation:
- Passing data from controller to view:
- Dependency Injection 📺 - Part 19 📑
- Benefits: Loose coupling, Easier unit testing
- Lifetime service registration 📺 - Part 44 📑
- Notes 📺 🖼️ - Consider: Service instance within current HTTP request.
builder.Services.AddSingleton()
- Creates a single instance of the service when it is first requested, and reuses that same instance in all the places where that service is needed - 3 4 5 6 7... So on and so foth.builder.Services.AddScoped()
- A new instance of a Scoped service is created once per request within the scope. For example, in a web application it creates 1 instance per each http request but uses the same instance in the other calls within that same web request. - 3 4 4 4 4 4... So on and so foth.builder.Services.AddTransient()
- A new instance of a Transient service is created each time it is requested. - 3 3 3 3 3... So on and so foth.
- ListView 📺 - Part 27 📑
- Layout View 📺 - Part 28 📑
- Render Sections in Layout Page 📺 - Part 29 📑
- For the organization of page elements. They can be optional or mandatory.
_ViewStart.cshtml
📺 - Part 30 📑_ViewImports.cshtml
📺 - Part 31 📑- Used to include common namespaces.
- View directives:
@addTagHelper
@removeTagHelper
@tagHelperPrefix
@model
@inherits
@inject
- Conventional Routing 📺 - Part 32 📑
- Attribute Routing 📺 - Part 33 📑
- Applied to the controllers or to the controller actions methods.
- NOTE: The controller route template is not combined with action method route template, if the route template on the action method begins with
/
or~/
- Tokens in attribute routing:
[Route("[controller]/[action]")]
- Video 34 is above.
- Notes: Similar to HTML Helpers. Server side components for HTML rendering. Use: Link generation, form creation, asset load, etc.
- Tag Helpers & HTML Helpers 📺 - Part 35 📑
- Why use Tag Helpers 📺 - Part 36 📑
- Image Tag Helper 📺 - Part 37 📑
- Provide cache-busting behaviour for static image files.
- Environment Tag Helper 📺 - Part 38 📑
- Navigation Menu 📺 - Part 39 📑
- Form Tag Helpers 📺 - Part 40 📑
Form Tag Helper
,Input Tag Helper
,Label Tag Helper
,Select Tag Helper
,TextArea Tag Helper
,Validation Tag Helper
- Model Binding 📺 - Part 41 📑
- "Model binding maps data in an HTTP request to controller action method parameters. The action parameters say be simple or complext types."
name
input attribute value is used for mapping.- Data available in the HTTP request (with preeminence order):
Form values
→Route values
→Query strings
- Update a model:
- Model Binding Not Working with FOREACH loop 📺 - Part 92 📑
- Model Validation 📺 - Part 42 📑
- Custom validation attributes 📺 - Part 76 📑
- Select list validation 📺 - Part 43 📑
- Introduction 📺 - Part 45 📑
- Notes:
- ORM, Domain Classes, Code/Database First, Database Provider Models
Domain & DBContext Classes
→EF Core
→DB Provider
→Actual DB
- Installation & Multilayer Web Application 📺 - Part 46 📑
Presentation Layer
→Business Layer
→Data Access Layer
DbContext
📺 - Part 47 📑- Using with SQL Server 📺 - Part 48 📑
- Connection string
- Repository Pattern 📺 - Part 49 📑
- Abstraction of the Data Access Layer, for CRUD operations. How to use
AddScoped
with SQL Server.
- Abstraction of the Data Access Layer, for CRUD operations. How to use
- Migrations 📺 - Part 50 📑
- Migrations keep the DB schema and app model classes in sync.
- Commands:
get-help about_entityframeworkcore
Add-Migration
Update-Database
- Seed Data to Database 📺 - Part 51 📑
- Keeping domain models and database schema in sync 📺 - Part 52 📑
Remove-Migration
- This video also explains how to remove migration that has already been applied to the database.
- File upoad 📺 - Part 53 📑
- Handling
404
Not Found Errors: - Correct Global Exception handling:
- Custom Error Page (for
ON DELETE NO ACTION
) 📺 - Part 90 📑
- Basics, Logging from console, Built-in Logging Providers 📺 - Part 61 📑
- Logging Exceptions 📺 - Part 62 📑
- Logging to a file 📺 - Part 63 📑
LogLevel
configuration 📺 - Part 64 📑
- Inherit from
IdentityDbContext
, add services, add middleware, generate tables 📺 - Part 65 📑 - Register new user 📺 - Part 66 📑
- Services:
UserManager
andSignInManager
📺 - Part 67 📑 - Password complexity 📺 - Part 68 📑
- Show/hide view elements using
@if (SignInManager.IsSignedIn(User)) { }
📺 - Part 69 📑 - Implementing log in functionality 📺 - Part 70 📑
LoginViewModel
, Login View, Login Actions in Account Controller.
- Authorizacion implementation - Types: Simple authorization, Role based, Claims based, Policy based.
- Extend
IdentityUser
class 📺 - Part 77 📑
- Create Roles 📺 - Part 78 📑
- Get list of roles 📺 - Part 79 📑
- Edit existing role 📺 - Part 80 📑
- Add or remove users 📺 - Part 81 📑
- Tables for: Users, Roles, UserRoles
- Role based authorization (RBAC) 📺 - Part 82 📑
- User role membership: Add/remove roles for user 📺
- List users, register new user and redirect correctly 📺 - Part 84 📑
- Edit user information, roles and claims 📺 - Part 85 📑
- Delete user 📺 - Part 86 📑
- Delete role 📺 - Part 88 📑
- Manager user roles 📺 - Part 91 📑
- Manage User Claims 📺 - Part 93 📑
- "Claim": Name-value pair used for making access control decisions.
- They are a piece of information about the user, NOT what the user can or cannot do.
- Claims are "policy based".
- Claims Based Authorization (CBAC) 📺 - Part 94 📑
- What are they? •
Services.AddAuthorization
•AddPolicy
•RequireClaim
• Use in controllers and actions • Combination of roles and policies.
- What are they? •
- Role Based Authorization (RBAC) Vs Claim Base Authorization (CBAC) 📺 - Part 95 📑
[Authorize(Roles = "Admin")]
is role based.[Authorize(Policy = "DeleteRolePolicy")]
is claim based.
- Authorization in views 📺 - Part 96 📑
- Claim based authorization checks in views.
- See part-83 for related information.
- Using "claim type" and "claim value" in policy based authorization 📺 - Part 98 📑
- Create custom authorization policy (Policy with multiple requirements) 📺 - Part 99 📑
- See "Part 100 Func delegate in C#" for related information.
- Custom authorization requirements and handlers - EXPLANATION 📺 - Part 100 📑
- BUILT-IN Authorization Requirement
- Policies with one requirement. →
RequireClaim
- Policies with multiple requirements:
- Simple relationships →
RequireClaim
+RequireRole
- Complex relationships →
RequireAssertion
- Simple relationships →
- Policies with one requirement. →
- CUSTOM Authorization Requirement
- Implement
IAuthorizationRequirement
→IAuthorizationHandler<T>
where T is the requirement
- Implement
- BUILT-IN Authorization Requirement
- Custom authorization requirements and handlers - EXAMPLE 📺 - Part 101 📑
- Multiple authorization handlers for a requirement 📺 - Part 102 📑
- Custom authorization handler: SUCCESS Vs FAILURE, and NOTHING (
Task.CompletedTask
) 📺 - Part 103 📑
- OFFICIAL DOCUMENTATION 📑
- Error when connecting from behind a bypassed proxy: You may need to unset these Windows environment variables.
- Introduction, how it works 📺 - Part 104 📑
- Create Google OAuth Credentials - Obtain Client Id & Secret 📺 - Part 105 📑
- https://console.cloud.google.com/
- Google+ API: https://console.cloud.google.com/marketplace/product/google/plus.googleapis.com
- Console work:
- Delete resource: https://console.cloud.google.com/cloud-resource-manager?organizationId=0
- Google Auth: https://console.cloud.google.com/auth/audience
- Credentials: https://console.cloud.google.com/apis/credentials
- NOTES for Visual Studio 2022:
- Visual Studio 2022 → Project properties → Debug
- Enable SSL. From here copy
https://localhost:44370/
and paste it in... - App URL:
https://localhost:44370/
- Copy, paste the same address in the followin section...
- Enable SSL. From here copy
- Visual Studio 2022 → Project properties → Debug
- NOTES for Google Cloud:
- Project name:
Employee Mgmt STS
- STS, stands for "Security Token Service" - Credentials for Web Application → OAuth 2.0 Client name:
Employee Mgmt Client
- Authorized JavaScript origins:
https://localhost:44370
- The HTTP origins that host your web application. - Authorized redirect URIs:
https://localhost:44370/signin-google
- Users will be redirected to this path after they have authenticated with Google.
- Authorized JavaScript origins:
- Project name:
- Google Authentication, setting up the UI and the authentication service 📺 - Part 106 📑
- Handle authenticated user information received from Google:
ExternalLoginCallback
Action 📺 - Part 107 📑
- Register application with Facebook 📺 - Part 108 📑
- https://developers.facebook.com/apps/
- App Name:
Employee Mgmt Client
- Use case:
Authenticate and request data from users with Facebook login
- App Name:
- https://developers.facebook.com/apps/-app-id-/add/ - Add Facebook login product, change settings
- Settings:
Client OAuth login
: OnValid OAuth Redirect URIs
:https://localhost:44370/signin-facebook
- Base URL comes from project properties → Debug → General → App URL
- Settings:
- https://developers.facebook.com/apps/640033055116902/use_cases/customize/
- Facebook Login → Permissions → email →
Add
- Facebook Login → Permissions → email →
- https://developers.facebook.com/apps/-app-id-/settings/basic/
- Privacy Policy URL:
https://localhost:44370/Home/Privacy
- User Data Deletion → Data deletion callback URL:
https://localhost:44370/Administration/DeleteUserData/Facebook
(The method has not been added) - Category:
Education
- App icon:
EmployeeManagement/EmployeeManagement/wwwroot/images/employees_1024x1024.png
- Privacy Policy URL:
- https://developers.facebook.com/apps/
- Facebook authentication code integration 📺 - Part 109 📑
- Why email confirmation is important for app security 📺 - Part 111 📑
- Block log in if email is not confirmed 📺 - Part 112 📑
- Email confirmation for internal accounts 📺 - Part 113 📑
- Using token providers.
- External login email confirmation 📺 - Part 114 📑
- External registration is allowed, but external login is blocked until email confirmation is performed.
- Password:
- Tokens:
- How Tokens are generated and validated 📺 - Part 117 📑
- Generated token contains:
- (
Token Creation Time
+User ID
+Token Purpose
+Security Stamp
) ← Encrypted and then Base64 Encoded
- (
- Generated token contains:
- Password reset token lifetime (built-in method) 📺 - Part 118 📑
- Password reset token lifetime (CUSTOM method) 📺 - Part 119 📑
- How Tokens are generated and validated 📺 - Part 117 📑
- Encryption and Decryption:
- Change Password 📺 - Part 121 📑
- With block user access to action controller example.
- Add password to local account linked to external login (Facebook, Google) 📺 - Part 122 📑
- Account lockout 📺 - Part 123 📑
- ASP.NET Core MVC Course Wrap Up 📺 - Part 124 📑
- Client side validation implementation 📺 - Part 74 📑
- Requirements (in this order):
jquery.js
,jquery.validate.js
,jquery.validate.unobtrusive.js
- Requirements (in this order):
- Remote validation 📺 - Part 75 📑
- Change default access denied route 📺 - Part 97 📑
- Cascading referential integrity constraint
- Secret Manager in ASP.NET Core 📺 - Part 110 📑
- Use: "Keep production secrets like database connection string, API and encryption keys out of source control."
Videos and tutorials mentioned in this course.
- Courses: https://www.pragimtech.com/course-category/free-online-courses/
- Playlists for courses: https://www.youtube.com/@Csharp-video-tutorialsBlogspot/playlists
Text version of the following tutorials, may be found in the video description.
- Some topics related to the main tutorial of this file:
LINQ Tutorial 📺 LINQ to SQL 📺 LINQ to XML 📺
- Extension methods 📺
- SQL Server Performance Tuning and Query Optimization 📺
- SQL Server Interview Questions and Answers 📺
- SQL Server tutorial for beginners 📺
- Cascading referential integrity constraint 📺 - Part 5
SQL Server | EF Core | Behavior |
---|---|---|
Delete rule | enum DeleteBehavior |
The enumeration representing the delete behavior in EF Core. |
NoAction | .ClientSetNull (0) |
If a parent entity is deleted, the dependent entity's foreign key is set to null in the client memory but throws if the database disallows it. |
- | .Restrict (1) |
Prevents deletion of the parent entity if related entities exist. |
SetNull | .SetNull (2) |
When a parent entity is deleted, foreign keys in dependent entities are set to null . |
Cascade | .Cascade (3) |
DEFAULT. When a parent entity is deleted, related child entities are also deleted. |
- | .ClientCascade (4) |
The dependent entities are deleted in client-side memory but require a save to propagate to the database. |
NoAction | .NoAction (5) |
EF Core does not perform any action, and the database enforces referential integrity constraints. |
SetDefault | .ClientNoAction (6) |
No action is performed on the dependent entities in the client; the database handles SET DEFAULT . |
- For Windows enviroment variables:
HTTP_PROXY = http://10.1.33.254:80
HTTPS_PROXY = https://10.1.33.254:80
NO_PROXY = localhost,127.0.0.1,::1,LOCALHOST
Configuration Source | Course Part | Override Order |
---|---|---|
appsettings.json |
9 | 1st |
appsettings.{env.EnvironmentName}.json |
- | 2nd |
User secrets | 110 | 3rd |
Environment variables | 14 | 4th |
Command-line arguments | - | 5th |
env.EnvironmentName
:Development
- Environment variables are configured at operating system level.
- Example:
Variable name
:ConnectionString:EmployeeDBConnection
Variable value
:Server=localhost;Database=EmployeeDB;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True;Encrypt=False
- .NET Standard: https://learn.microsoft.com/en-us/dotnet/standard/net-standard
- UPDATE/UPGRADE:
- Upgrade to a new .NET version: https://learn.microsoft.com/en-us/dotnet/core/install/upgrade
- Migrate from Windows Forms .NET Framework to .NET: https://learn.microsoft.com/en-us/dotnet/desktop/winforms/migration/
- Overview of porting from .NET Framework to .NET: https://learn.microsoft.com/en-us/dotnet/core/porting/