SlideShare a Scribd company logo
1 of 11
Dot Net Training
Authorization in Asp.net (Part II)
Dot Net Training
Claims Based Authorization
On creating an identity it might be assigned one or more claims that are issued by a
trusted party. A claim is a name-value pair that depicts what the subject is, not what
the subject can do. E.g. you might have a Driving License, issued by a local driving
authority. Your driver’s license has your DOB on it. In this case, the claim name would
be DOB , the claim value would be your DOB, e.g. 8th June 1970 and the person who
issued it would be the driving license authority. Claims based authorization in simple
words, access the value of a claim and permits access to a resource that is based
upon the value. For example, if you want access to a night club the permission
process might be:
The security officer at the door would evaluate the value of your date of birth claim and
whether they trust the issuer before granting you access.
An identity can contain multiple claims with multiple values and has multiple claims of
the same type.
Dot Net Training
Adding claims checks
Claim based authorization checks are declarative. The developer fixes them within
their code, against a controller or an action within a controller, specifying claims which
the current user should possess, and optionally the value the claim must hold to
access the requested resource. Requirements of claims are policy based, the
developer should build and register a policy expressing the claims requirements.
The simplest type of affirmation sees for the existence of a claim and does not check
the value.
First, you need to create and list the policy. This takes place as part of the
Authorization service configuration, which normally takes part in ConfigureServices() in
your Startup.cs file.
Dot Net Training
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddAuthorization(options =>
{
options.AddPolicy(“EmployeeOnly”, policy =>
policy.RequireClaim(“EmployeeNumber”));
});
}
In this case the policy EmployeeOnly, checks for the presence of an EmployeeNumber
claim of the current name.
Dot Net Training
Then you can apply the policy using the Policy property on the AuthorizeAttribute
feature to define the policy name;
[Authorize(Policy = "EmployeeOnly")]
public IActionResult VacationBalance()
{
return View();
}
The AuthorizeAttribute feature can be applied to an entire controller, in this instance,
only names matching the policy will be allowed an entry to any Action on the controller.
Dot Net Training
[Authorize(Policy = "EmployeeOnly")]
public class VacationController : Controller
{
public ActionResult VacationBalance()
{
}
}
If you have a controller that is covered by the AuthorizeAttribute feature, but want to
permit anonymous access to particular actions you apply the
AllowAnonymousAttribute feature;
Dot Net Training
[Authorize(Policy = "EmployeeOnly")]
public class VacationController : Controller
{
public ActionResult VacationBalance()
{
}
[AllowAnonymous]
public ActionResult VacationPolicy()
{
}
}
.
Dot Net Training
Most claims come with a value. You could specify a list of permitted values when
creating the policy. The following example is only applicable for employees whose
employee number was 1, 2, 3, 4 or 5.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddAuthorization(options =>
{
options.AddPolicy(“Founders”, policy =>
policy.RequireClaim(“EmployeeNumber”, “1”, “2”, “3”, “4”, “5”));
}
}
Dot Net Training
Multiple Policy Evaluation
If you apply many policies to a controller or action then all policies must progress
before access is granted. For example;
[Authorize(Policy = "EmployeeOnly")]
public class SalaryController : Controller
{
public ActionResult Payslip()
{
}
[Authorize(Policy = "HumanResources")]
public ActionResult UpdateSalary()
Dot Net Training
In the above example, any name that fulfills the policy of EmployeeOnly can access
the Payslip action as that policy is made compulsory on the controller. But in order to
take up the UpdateSalary action, it (identity) must please both the EmployeeOnly and
the HumanResources policy.
If you need more complicated policies, e.g. taking a DOB claim, calculating an age
from it then checking the age is 21 or more than that you need to write custom policy
handlers.
If you want to learn ASP.Net and improve yourself in .NET training, CRB Tech
Solutions would be of great help for you. Join with advanced program in ASP.Net
course.
Stay tuned to CRB Tech reviews for more technical and other resources.
Thank You..!
Dot Net Training

More Related Content

Viewers also liked

Social story for aiken
Social story for aikenSocial story for aiken
Social story for aikenBecca Dupree
 
Learn about dot net attributes
Learn about dot net attributesLearn about dot net attributes
Learn about dot net attributessonia merchant
 
Судебная практика по признанию фактических трудовых отношений и установлению ...
Судебная практика по признанию фактических трудовых отношений и установлению ...Судебная практика по признанию фактических трудовых отношений и установлению ...
Судебная практика по признанию фактических трудовых отношений и установлению ...Manpower Group Russia&CIS
 
School rules social story
School rules social storySchool rules social story
School rules social storyBecca Dupree
 
Развитие бизнеса для получения конкурентных преимуществ при использовании аут...
Развитие бизнеса для получения конкурентных преимуществ при использовании аут...Развитие бизнеса для получения конкурентных преимуществ при использовании аут...
Развитие бизнеса для получения конкурентных преимуществ при использовании аут...Manpower Group Russia&CIS
 
Эпоха человеческого капитала:кадровый потенциал как основа успеха в бизнее
Эпоха человеческого капитала:кадровый потенциал как основа успеха в бизнееЭпоха человеческого капитала:кадровый потенциал как основа успеха в бизнее
Эпоха человеческого капитала:кадровый потенциал как основа успеха в бизнееManpower Group Russia&CIS
 
Судебная практика разрешения споров, связанных с нарушениями законодательства...
Судебная практика разрешения споров, связанных с нарушениями законодательства...Судебная практика разрешения споров, связанных с нарушениями законодательства...
Судебная практика разрешения споров, связанных с нарушениями законодательства...Manpower Group Russia&CIS
 
Taking medicine social story
Taking medicine social storyTaking medicine social story
Taking medicine social storyBecca Dupree
 

Viewers also liked (10)

Social story for aiken
Social story for aikenSocial story for aiken
Social story for aiken
 
Learn about dot net attributes
Learn about dot net attributesLearn about dot net attributes
Learn about dot net attributes
 
PROFILE
PROFILEPROFILE
PROFILE
 
Судебная практика по признанию фактических трудовых отношений и установлению ...
Судебная практика по признанию фактических трудовых отношений и установлению ...Судебная практика по признанию фактических трудовых отношений и установлению ...
Судебная практика по признанию фактических трудовых отношений и установлению ...
 
School rules social story
School rules social storySchool rules social story
School rules social story
 
Развитие бизнеса для получения конкурентных преимуществ при использовании аут...
Развитие бизнеса для получения конкурентных преимуществ при использовании аут...Развитие бизнеса для получения конкурентных преимуществ при использовании аут...
Развитие бизнеса для получения конкурентных преимуществ при использовании аут...
 
Эпоха человеческого капитала:кадровый потенциал как основа успеха в бизнее
Эпоха человеческого капитала:кадровый потенциал как основа успеха в бизнееЭпоха человеческого капитала:кадровый потенциал как основа успеха в бизнее
Эпоха человеческого капитала:кадровый потенциал как основа успеха в бизнее
 
Судебная практика разрешения споров, связанных с нарушениями законодательства...
Судебная практика разрешения споров, связанных с нарушениями законодательства...Судебная практика разрешения споров, связанных с нарушениями законодательства...
Судебная практика разрешения споров, связанных с нарушениями законодательства...
 
R N DUBEY
R N DUBEYR N DUBEY
R N DUBEY
 
Taking medicine social story
Taking medicine social storyTaking medicine social story
Taking medicine social story
 

More from sonia merchant

What does dot net hold for 2016?
What does dot net hold for 2016?What does dot net hold for 2016?
What does dot net hold for 2016?sonia merchant
 
What does .net hold for 2016?
What does .net hold for 2016?What does .net hold for 2016?
What does .net hold for 2016?sonia merchant
 
Data protection api's in asp dot net
Data protection api's in asp dot netData protection api's in asp dot net
Data protection api's in asp dot netsonia merchant
 
Authorization in asp dot net part 2
Authorization in asp dot net part 2Authorization in asp dot net part 2
Authorization in asp dot net part 2sonia merchant
 
Asp dot-net core problems and fixes
Asp dot-net core problems and fixes Asp dot-net core problems and fixes
Asp dot-net core problems and fixes sonia merchant
 
Search page-with-elasticsearch-and-dot-net
Search page-with-elasticsearch-and-dot-netSearch page-with-elasticsearch-and-dot-net
Search page-with-elasticsearch-and-dot-netsonia merchant
 
Build a-search-page-with-elastic search-and-dot-net
Build a-search-page-with-elastic search-and-dot-netBuild a-search-page-with-elastic search-and-dot-net
Build a-search-page-with-elastic search-and-dot-netsonia merchant
 
How to optimize asp dot-net application
How to optimize asp dot-net applicationHow to optimize asp dot-net application
How to optimize asp dot-net applicationsonia merchant
 
How to optimize asp dot net application ?
How to optimize asp dot net application ?How to optimize asp dot net application ?
How to optimize asp dot net application ?sonia merchant
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributessonia merchant
 
Owin and-katana-overview
Owin and-katana-overviewOwin and-katana-overview
Owin and-katana-overviewsonia merchant
 
Top 15-asp-dot-net-interview-questions-and-answers
Top 15-asp-dot-net-interview-questions-and-answersTop 15-asp-dot-net-interview-questions-and-answers
Top 15-asp-dot-net-interview-questions-and-answerssonia merchant
 
Next generation asp.net v next
Next generation asp.net v nextNext generation asp.net v next
Next generation asp.net v nextsonia merchant
 
Dot net universal apps
Dot net universal appsDot net universal apps
Dot net universal appssonia merchant
 
Browser frame building with c# and vb dot net
Browser frame building  with c# and vb dot netBrowser frame building  with c# and vb dot net
Browser frame building with c# and vb dot netsonia merchant
 
A simplest-way-to-reconstruct-.net-framework
A simplest-way-to-reconstruct-.net-frameworkA simplest-way-to-reconstruct-.net-framework
A simplest-way-to-reconstruct-.net-frameworksonia merchant
 
Silverlight versions-features
Silverlight versions-featuresSilverlight versions-features
Silverlight versions-featuressonia merchant
 

More from sonia merchant (20)

What does dot net hold for 2016?
What does dot net hold for 2016?What does dot net hold for 2016?
What does dot net hold for 2016?
 
What does .net hold for 2016?
What does .net hold for 2016?What does .net hold for 2016?
What does .net hold for 2016?
 
Data protection api's in asp dot net
Data protection api's in asp dot netData protection api's in asp dot net
Data protection api's in asp dot net
 
Authorization p iv
Authorization p ivAuthorization p iv
Authorization p iv
 
Authorization iii
Authorization iiiAuthorization iii
Authorization iii
 
Authorization in asp dot net part 2
Authorization in asp dot net part 2Authorization in asp dot net part 2
Authorization in asp dot net part 2
 
Asp dot-net core problems and fixes
Asp dot-net core problems and fixes Asp dot-net core problems and fixes
Asp dot-net core problems and fixes
 
Search page-with-elasticsearch-and-dot-net
Search page-with-elasticsearch-and-dot-netSearch page-with-elasticsearch-and-dot-net
Search page-with-elasticsearch-and-dot-net
 
Build a-search-page-with-elastic search-and-dot-net
Build a-search-page-with-elastic search-and-dot-netBuild a-search-page-with-elastic search-and-dot-net
Build a-search-page-with-elastic search-and-dot-net
 
How to optimize asp dot-net application
How to optimize asp dot-net applicationHow to optimize asp dot-net application
How to optimize asp dot-net application
 
How to optimize asp dot net application ?
How to optimize asp dot net application ?How to optimize asp dot net application ?
How to optimize asp dot net application ?
 
10 things to remember
10 things to remember10 things to remember
10 things to remember
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributes
 
Owin and-katana-overview
Owin and-katana-overviewOwin and-katana-overview
Owin and-katana-overview
 
Top 15-asp-dot-net-interview-questions-and-answers
Top 15-asp-dot-net-interview-questions-and-answersTop 15-asp-dot-net-interview-questions-and-answers
Top 15-asp-dot-net-interview-questions-and-answers
 
Next generation asp.net v next
Next generation asp.net v nextNext generation asp.net v next
Next generation asp.net v next
 
Dot net universal apps
Dot net universal appsDot net universal apps
Dot net universal apps
 
Browser frame building with c# and vb dot net
Browser frame building  with c# and vb dot netBrowser frame building  with c# and vb dot net
Browser frame building with c# and vb dot net
 
A simplest-way-to-reconstruct-.net-framework
A simplest-way-to-reconstruct-.net-frameworkA simplest-way-to-reconstruct-.net-framework
A simplest-way-to-reconstruct-.net-framework
 
Silverlight versions-features
Silverlight versions-featuresSilverlight versions-features
Silverlight versions-features
 

Recently uploaded

fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 

Recently uploaded (20)

fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 

Authorization in asp dot-net (part ii)

  • 2. Dot Net Training Claims Based Authorization On creating an identity it might be assigned one or more claims that are issued by a trusted party. A claim is a name-value pair that depicts what the subject is, not what the subject can do. E.g. you might have a Driving License, issued by a local driving authority. Your driver’s license has your DOB on it. In this case, the claim name would be DOB , the claim value would be your DOB, e.g. 8th June 1970 and the person who issued it would be the driving license authority. Claims based authorization in simple words, access the value of a claim and permits access to a resource that is based upon the value. For example, if you want access to a night club the permission process might be: The security officer at the door would evaluate the value of your date of birth claim and whether they trust the issuer before granting you access. An identity can contain multiple claims with multiple values and has multiple claims of the same type.
  • 3. Dot Net Training Adding claims checks Claim based authorization checks are declarative. The developer fixes them within their code, against a controller or an action within a controller, specifying claims which the current user should possess, and optionally the value the claim must hold to access the requested resource. Requirements of claims are policy based, the developer should build and register a policy expressing the claims requirements. The simplest type of affirmation sees for the existence of a claim and does not check the value. First, you need to create and list the policy. This takes place as part of the Authorization service configuration, which normally takes part in ConfigureServices() in your Startup.cs file.
  • 4. Dot Net Training public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddAuthorization(options => { options.AddPolicy(“EmployeeOnly”, policy => policy.RequireClaim(“EmployeeNumber”)); }); } In this case the policy EmployeeOnly, checks for the presence of an EmployeeNumber claim of the current name.
  • 5. Dot Net Training Then you can apply the policy using the Policy property on the AuthorizeAttribute feature to define the policy name; [Authorize(Policy = "EmployeeOnly")] public IActionResult VacationBalance() { return View(); } The AuthorizeAttribute feature can be applied to an entire controller, in this instance, only names matching the policy will be allowed an entry to any Action on the controller.
  • 6. Dot Net Training [Authorize(Policy = "EmployeeOnly")] public class VacationController : Controller { public ActionResult VacationBalance() { } } If you have a controller that is covered by the AuthorizeAttribute feature, but want to permit anonymous access to particular actions you apply the AllowAnonymousAttribute feature;
  • 7. Dot Net Training [Authorize(Policy = "EmployeeOnly")] public class VacationController : Controller { public ActionResult VacationBalance() { } [AllowAnonymous] public ActionResult VacationPolicy() { } } .
  • 8. Dot Net Training Most claims come with a value. You could specify a list of permitted values when creating the policy. The following example is only applicable for employees whose employee number was 1, 2, 3, 4 or 5. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddAuthorization(options => { options.AddPolicy(“Founders”, policy => policy.RequireClaim(“EmployeeNumber”, “1”, “2”, “3”, “4”, “5”)); } }
  • 9. Dot Net Training Multiple Policy Evaluation If you apply many policies to a controller or action then all policies must progress before access is granted. For example; [Authorize(Policy = "EmployeeOnly")] public class SalaryController : Controller { public ActionResult Payslip() { } [Authorize(Policy = "HumanResources")] public ActionResult UpdateSalary()
  • 10. Dot Net Training In the above example, any name that fulfills the policy of EmployeeOnly can access the Payslip action as that policy is made compulsory on the controller. But in order to take up the UpdateSalary action, it (identity) must please both the EmployeeOnly and the HumanResources policy. If you need more complicated policies, e.g. taking a DOB claim, calculating an age from it then checking the age is 21 or more than that you need to write custom policy handlers. If you want to learn ASP.Net and improve yourself in .NET training, CRB Tech Solutions would be of great help for you. Join with advanced program in ASP.Net course. Stay tuned to CRB Tech reviews for more technical and other resources.