SlideShare une entreprise Scribd logo
1  sur  30
Télécharger pour lire hors ligne
ASP.NET MVC
MVC Core
Eng. Basma Hussien
MVC Filters
MVC Filters
• In ASP.NET MVC, a user request is routed to the appropriate controller and action
method. However, there may be circumstances where you want to execute some logic
before or after an action method executes. ASP.NET MVC provides filters for this
purpose.
• ASP.NET MVC Filter is a custom class where you can write custom logic to execute
before or after an action method executes. Filters can be applied to an action method or
controller
• Filters can be applied to an action method or controller
• You could apply filters in a declarative or programmatic way:
• Declarative means by applying a filter attribute to an action method or
controller class
• Programmatic means by implementing a corresponding interface or abstract
class
MVC Filters (Cont.)
• The ASP.NET MVC framework supports four different types of filters:
• Authorization Filters − Implements the IAuthorizationFilter attribute.
• Action Filters − Implements the IActionFilter attribute.
• Result Filters − Implements the IResultFilter attribute.
• Exception Filters − Implements the IExceptionFilter attribute.
• Filters are executed in the order listed above. For example, authorization filters are always
executed before action filters and exception filters are always executed after every other type of
filter.
• Authorization filters are used to implement authentication and authorization for controller
actions.
MVC Filters Types
MVC Filters Types
• MVC provides different types of filters. The following table list filter types, built-in
filters, and interface that must be implemented to create custom filters.
Custom Filters
• To create your own custom filter, ASP.NET MVC framework provides a
base class which is known as ActionFilterAttribute. This class
implements both IActionFilter and IResultFilter interfaces and both are
derived from the Filter class.
• Action selector is the attribute that can be applied to the action methods. It
helps the routing engine to select the correct action method to handle a
particular request. MVC 5 includes the following action selector attributes:
• ActionName
• NonAction
• ActionVerbs (AcceptVerbs)
Action Selectors
[ActionName("Find")]
public ActionResult GetById(int id)
{
return View();
}
Action Selectors (Cont.)
[NonAction]
public Student GetStudent(int id)
{
return studentList.Where(s => s.StudentId ==
id).FirstOrDefault();
}
Conventional routing
& Attribute Routing
• In ASP.NET Core, routing is handled by routing middleware, which matches the URLs of
incoming requests to actions or other endpoints.
• Controller actions are either conventionally routed or attribute-routed.
• Conventional routing is similar to the route table approach used in ASP.NET MVC and Web
API. Whether you're using conventional, attribute, or both, you need to configure your app to
use the routing middleware.
• To use the middleware, add the following code to your Program.cs file:
• app.UseRouting();
Routing
Conventional Routing
• With conventional routing, you set up one or more conventions that will be used to match incoming
URLs to endpoints in the app.
• In ASP.NET Core, these endpoints may be controller actions, like in ASP.NET MVC or Web API.
• In addition to (UseRouting), this configuration specifies a default routing convention, which is the fairly
standard {controller}/{action}/{id?} pattern that's been recommended since the first versions of
ASP.NET MVC:
• app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
Conventional Routing
Attribute Routing
• Apply attribute routing on any action:
• //...../Order/GetOrders/3
• //...../customers/3/Orders
[Route("customers/{customerId}/orders")]
public ActionResult GetOrders(int customerId) {…}
Attribute Routing
• RoutePrefix on a controller:
[Route(“Company/Finance")]
• Then on each action in controller you should specify a specific route:
[Route("customers/{id}")]
[Route("")]
RoutePrefix
Use a tilde (~) on the method attribute to override the route prefix:
[Route("mvc/books")]
public class BooksController : Controller
{
// GET /mvc/authors/1/books
[Route("~/mvc/authors/{authorId:int}/books")]
public IEnumerable<Book> GetByAuthor(int authorId) { ... }
}
Override RoutePrefix
• To apply Route Constraints:
[Route("users/{id:int:min(10)}")]
public User GetUserById(int id) { ... }
Route Constraints
Constraint Description Example
Alpha Matches uppercase or lowercase Latin alphabet characters (a-z,
A-Z)
{x:alpha}
Bool Matches a Boolean value. {x:bool}
Datetime Matches a DateTime value. {x:datetime}
Decimal Matches a decimal value. {x:decimal}
Double Matches a 64-bit floating-point value. {x:double}
Float Matches a 32-bit floating-point value. {x:float}
Guid Matches a GUID value. {x:guid}
Int Matches a 32-bit integer value. {x:int}
Length Matches a string with the specified length or
within a specified range of lengths.
{x:length(6)}
{x:length(1,20)}
Long Matches a 64-bit integer value. {x:long}
Max Matches an integer with a maximum value. {x:max(10)}
maxlength Matches a string with a maximum length. {x:maxlength(10)}
Min Matches an integer with a minimum value. {x:min(10)}
minlength Matches a string with a minimum length. {x:minlength(10)}
Range Matches an integer within a range of values. {x:range(10,50)}
Regex Matches a regular expression. {x:regex(^d{3}-d{3}-
d{4}$)}
Membership & Identity Authentication
ASP.NET Membership
• It was designed to solve site membership requirements that were
common in 2005, which involved Forms Authentication, and a
SQL Server database for user names, passwords, and profile data.
• Today there is a much broader array of data storage options for
web applications, and most developers want to enable their sites to
use social identity providers for authentication and authorization
functionality.
ASP.NET Membership Limitations
• The database schema was designed for SQL Server and you can't
change it.
• Membership database is limited to describe users identity.
• Since the log-in/log-out functionality is based on Forms
Authentication, the membership system can't use OWIN.
ASP.NET Identity
ASP.NET Identity was developed with the following goals:
• One ASP.NET Identity system
• Persistence control
• Claims Based
• Role provider
• Social Login Providers
• OWIN Integration
• Unit testability
Validate MVC App
Using External Logins
Live Accounts Authentication
• You should Choose “Individual User” Authentication MVC template
when creating your web application
• You have to create a project on “Google.developer.console” or what so
ever provider you will use for authentication process delegation
• You need a “Client ID & Client Secret” to be able to use provider
API for authenticating your web application
ASP.NET MVC_Routing_Authentication_Aurhorization.pdf

Contenu connexe

Similaire à ASP.NET MVC_Routing_Authentication_Aurhorization.pdf

MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_HourDilip Patel
 
Using MVC with Kentico 8
Using MVC with Kentico 8Using MVC with Kentico 8
Using MVC with Kentico 8Thomas Robbins
 
Mvc interview questions – deep dive jinal desai
Mvc interview questions – deep dive   jinal desaiMvc interview questions – deep dive   jinal desai
Mvc interview questions – deep dive jinal desaijinaldesailive
 
Overview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company indiaOverview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company indiaJignesh Aakoliya
 
Introduction to ASP.Net MVC
Introduction to ASP.Net MVCIntroduction to ASP.Net MVC
Introduction to ASP.Net MVCSagar Kamate
 
(ATS6-DEV03) Building an Enterprise Web Solution with AEP
(ATS6-DEV03) Building an Enterprise Web Solution with AEP(ATS6-DEV03) Building an Enterprise Web Solution with AEP
(ATS6-DEV03) Building an Enterprise Web Solution with AEPBIOVIA
 
Asp.net mvc presentation by Nitin Sawant
Asp.net mvc presentation by Nitin SawantAsp.net mvc presentation by Nitin Sawant
Asp.net mvc presentation by Nitin SawantNitin Sawant
 
Asp 1-mvc introduction
Asp 1-mvc introductionAsp 1-mvc introduction
Asp 1-mvc introductionFajar Baskoro
 
Unit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptxUnit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptxAbhijayKulshrestha1
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs WorkshopRan Wahle
 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3Ilio Catallo
 
Integrating Servlets and JSP (The MVC Architecture)
Integrating Servlets and JSP  (The MVC Architecture)Integrating Servlets and JSP  (The MVC Architecture)
Integrating Servlets and JSP (The MVC Architecture)Amit Ranjan
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...WebStackAcademy
 
Asp.net mvc basic introduction
Asp.net mvc basic introductionAsp.net mvc basic introduction
Asp.net mvc basic introductionBhagath Gopinath
 
Auto fac mvc以及進階應用(一)
Auto fac mvc以及進階應用(一)Auto fac mvc以及進階應用(一)
Auto fac mvc以及進階應用(一)LearningTech
 

Similaire à ASP.NET MVC_Routing_Authentication_Aurhorization.pdf (20)

MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
Using MVC with Kentico 8
Using MVC with Kentico 8Using MVC with Kentico 8
Using MVC with Kentico 8
 
Mvc interview questions – deep dive jinal desai
Mvc interview questions – deep dive   jinal desaiMvc interview questions – deep dive   jinal desai
Mvc interview questions – deep dive jinal desai
 
Overview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company indiaOverview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company india
 
MVC 4
MVC 4MVC 4
MVC 4
 
Introduction to ASP.Net MVC
Introduction to ASP.Net MVCIntroduction to ASP.Net MVC
Introduction to ASP.Net MVC
 
(ATS6-DEV03) Building an Enterprise Web Solution with AEP
(ATS6-DEV03) Building an Enterprise Web Solution with AEP(ATS6-DEV03) Building an Enterprise Web Solution with AEP
(ATS6-DEV03) Building an Enterprise Web Solution with AEP
 
Asp.net,mvc
Asp.net,mvcAsp.net,mvc
Asp.net,mvc
 
Asp.net mvc presentation by Nitin Sawant
Asp.net mvc presentation by Nitin SawantAsp.net mvc presentation by Nitin Sawant
Asp.net mvc presentation by Nitin Sawant
 
Asp 1-mvc introduction
Asp 1-mvc introductionAsp 1-mvc introduction
Asp 1-mvc introduction
 
Unit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptxUnit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptx
 
Mvc
MvcMvc
Mvc
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3
 
Integrating Servlets and JSP (The MVC Architecture)
Integrating Servlets and JSP  (The MVC Architecture)Integrating Servlets and JSP  (The MVC Architecture)
Integrating Servlets and JSP (The MVC Architecture)
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...
 
Asp.net mvc basic introduction
Asp.net mvc basic introductionAsp.net mvc basic introduction
Asp.net mvc basic introduction
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
 
Auto fac mvc以及進階應用(一)
Auto fac mvc以及進階應用(一)Auto fac mvc以及進階應用(一)
Auto fac mvc以及進階應用(一)
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 

Dernier

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 

Dernier (20)

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 

ASP.NET MVC_Routing_Authentication_Aurhorization.pdf

  • 3. MVC Filters • In ASP.NET MVC, a user request is routed to the appropriate controller and action method. However, there may be circumstances where you want to execute some logic before or after an action method executes. ASP.NET MVC provides filters for this purpose. • ASP.NET MVC Filter is a custom class where you can write custom logic to execute before or after an action method executes. Filters can be applied to an action method or controller
  • 4. • Filters can be applied to an action method or controller • You could apply filters in a declarative or programmatic way: • Declarative means by applying a filter attribute to an action method or controller class • Programmatic means by implementing a corresponding interface or abstract class MVC Filters (Cont.)
  • 5. • The ASP.NET MVC framework supports four different types of filters: • Authorization Filters − Implements the IAuthorizationFilter attribute. • Action Filters − Implements the IActionFilter attribute. • Result Filters − Implements the IResultFilter attribute. • Exception Filters − Implements the IExceptionFilter attribute. • Filters are executed in the order listed above. For example, authorization filters are always executed before action filters and exception filters are always executed after every other type of filter. • Authorization filters are used to implement authentication and authorization for controller actions. MVC Filters Types
  • 6. MVC Filters Types • MVC provides different types of filters. The following table list filter types, built-in filters, and interface that must be implemented to create custom filters.
  • 7. Custom Filters • To create your own custom filter, ASP.NET MVC framework provides a base class which is known as ActionFilterAttribute. This class implements both IActionFilter and IResultFilter interfaces and both are derived from the Filter class.
  • 8.
  • 9.
  • 10. • Action selector is the attribute that can be applied to the action methods. It helps the routing engine to select the correct action method to handle a particular request. MVC 5 includes the following action selector attributes: • ActionName • NonAction • ActionVerbs (AcceptVerbs) Action Selectors
  • 11. [ActionName("Find")] public ActionResult GetById(int id) { return View(); } Action Selectors (Cont.) [NonAction] public Student GetStudent(int id) { return studentList.Where(s => s.StudentId == id).FirstOrDefault(); }
  • 13. • In ASP.NET Core, routing is handled by routing middleware, which matches the URLs of incoming requests to actions or other endpoints. • Controller actions are either conventionally routed or attribute-routed. • Conventional routing is similar to the route table approach used in ASP.NET MVC and Web API. Whether you're using conventional, attribute, or both, you need to configure your app to use the routing middleware. • To use the middleware, add the following code to your Program.cs file: • app.UseRouting(); Routing
  • 15. • With conventional routing, you set up one or more conventions that will be used to match incoming URLs to endpoints in the app. • In ASP.NET Core, these endpoints may be controller actions, like in ASP.NET MVC or Web API. • In addition to (UseRouting), this configuration specifies a default routing convention, which is the fairly standard {controller}/{action}/{id?} pattern that's been recommended since the first versions of ASP.NET MVC: • app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); Conventional Routing
  • 17. • Apply attribute routing on any action: • //...../Order/GetOrders/3 • //...../customers/3/Orders [Route("customers/{customerId}/orders")] public ActionResult GetOrders(int customerId) {…} Attribute Routing
  • 18. • RoutePrefix on a controller: [Route(“Company/Finance")] • Then on each action in controller you should specify a specific route: [Route("customers/{id}")] [Route("")] RoutePrefix
  • 19. Use a tilde (~) on the method attribute to override the route prefix: [Route("mvc/books")] public class BooksController : Controller { // GET /mvc/authors/1/books [Route("~/mvc/authors/{authorId:int}/books")] public IEnumerable<Book> GetByAuthor(int authorId) { ... } } Override RoutePrefix
  • 20. • To apply Route Constraints: [Route("users/{id:int:min(10)}")] public User GetUserById(int id) { ... } Route Constraints
  • 21. Constraint Description Example Alpha Matches uppercase or lowercase Latin alphabet characters (a-z, A-Z) {x:alpha} Bool Matches a Boolean value. {x:bool} Datetime Matches a DateTime value. {x:datetime} Decimal Matches a decimal value. {x:decimal} Double Matches a 64-bit floating-point value. {x:double} Float Matches a 32-bit floating-point value. {x:float} Guid Matches a GUID value. {x:guid} Int Matches a 32-bit integer value. {x:int}
  • 22. Length Matches a string with the specified length or within a specified range of lengths. {x:length(6)} {x:length(1,20)} Long Matches a 64-bit integer value. {x:long} Max Matches an integer with a maximum value. {x:max(10)} maxlength Matches a string with a maximum length. {x:maxlength(10)} Min Matches an integer with a minimum value. {x:min(10)} minlength Matches a string with a minimum length. {x:minlength(10)} Range Matches an integer within a range of values. {x:range(10,50)} Regex Matches a regular expression. {x:regex(^d{3}-d{3}- d{4}$)}
  • 23. Membership & Identity Authentication
  • 24. ASP.NET Membership • It was designed to solve site membership requirements that were common in 2005, which involved Forms Authentication, and a SQL Server database for user names, passwords, and profile data. • Today there is a much broader array of data storage options for web applications, and most developers want to enable their sites to use social identity providers for authentication and authorization functionality.
  • 25. ASP.NET Membership Limitations • The database schema was designed for SQL Server and you can't change it. • Membership database is limited to describe users identity. • Since the log-in/log-out functionality is based on Forms Authentication, the membership system can't use OWIN.
  • 26. ASP.NET Identity ASP.NET Identity was developed with the following goals: • One ASP.NET Identity system • Persistence control • Claims Based • Role provider • Social Login Providers • OWIN Integration • Unit testability
  • 27.
  • 28. Validate MVC App Using External Logins
  • 29. Live Accounts Authentication • You should Choose “Individual User” Authentication MVC template when creating your web application • You have to create a project on “Google.developer.console” or what so ever provider you will use for authentication process delegation • You need a “Client ID & Client Secret” to be able to use provider API for authenticating your web application