SlideShare a Scribd company logo
1 of 30
Download to read offline
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

More Related Content

Similar to 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
 

Similar to 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
 

Recently uploaded

The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
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
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 

Recently uploaded (20)

The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
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...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 

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