SlideShare ist ein Scribd-Unternehmen logo
1 von 26
ASP.NET MVC
  [TITLE]
Best Practices
WHO’S THIS GUY




• Malisa Ncube
• Software Engineer at Infectious Diseases Institute
  (Uganda)
• Blogger – http://geekswithblogs.net/malisancube
• Follow me on Twitter handle - @malisancube
• My email is dev@malisancube.com
• Leader of Uganda .NET Usergroup
                                                   #MSOpenDoor
• Urban Artist
• High sense of humor
AGENDA


•   ASP.NET MVC Best Practices
•   A bit of ASP.NET MVC 4 Preview
•   We’ll see
•   Conclusion
•   Q&A
What is ASP.NET MVC?
What is ASP.NET MVC?

  • Model: The model contains the core information for an
    application. This includes the data and validation rules
    as well as data access and aggregation logic.
  • View: The view encapsulates the presentation of the
    application, and in ASP.NET this is typically the HTML
    markup.
  • Controller: The controller contains the control-flow logic.
    It interacts with the Model and Views to control the flow
    of information and execution of the application
What is ASP.NET MVC? (Continued)

  • Opensource – Released under MSL for Pre release
    components. http://aspnet.codeplex.com
  • Proven: There are many sites that are using ASP.NET
    MVC framework and many resources.
  • Testable: Enables good software development
    practices.
Practices
1) Isolate your layers properly.

  • Use the ViewModel for transmitting data to the view.
    They should be simple POCO de-normalised objects.
  • Use the Domain Model Entities for persistence,
    validation, Behaviours and complex relationships .
    Mapping with ViewModel can be done with tools like
    Automapper.
1) Isolate your layers properly (Continued).

  • Use Controllers for selecting the view to be shown and
    not for business logic.
  • Use the view for displaying Html which will be rendered
    by the browser. Not for business logic.
  • Use Services/Repositories for manipulating business
    objects.




  Let’s see come code
2) Use the PRG (PostRedirectGet) pattern

  •   Prevent reposts to the form
  •   Issues an HTTP302 with temporary redirect
  •   Watch out for Json redirects. Check the type of requests.
  •   Use proper verbs [HttpPost], [HttpGet] on you controllers
3) Secure site from forgery


  • Confused deputy problem (A confused deputy is a
    computer program that is innocently fooled by some
    other party into misusing its authority)

  • Prevent (cross site request Forgery)CSRF/XSRF
  • Prevent (cross site request Forgery)CSRF/XSRF With
    Ajax
  • Use Anti-forgery helpers for form posts
    @Html.AntiForgeryToken and
    ValidateAntiForgeryTokenAttribute which peeks into
    Request.Form collection for antiforgery token
4) Make you application testable, maintainable and extensible

  • Use IoC to make your application testable
  • Have actual tests for different segments of your
    application.
  • You can scaffold the application using NuGet packages
    like MvcScaffold and include the repository and unit
    tests.




  Let’s see come code
5) Write clean code


  • Use Action Filters for crosscutting concerns.
  • - They help clean up your code by giving you a
    declarative approach to programming, similar to Aspect
    Oriented programming. More specifically Postsharp.
  • - Handling errors, Authorisation, Tracing.




  Let’s see come code
6) Use strongly typed views


  • You may decide to inherit behaviour of all views from a
    certain base class.
  • Avoid the ViewBag




  Let’s see come code
7) JSON endpoints



  • All JSON endpoints require [HttpPost] to prevent JSON
    hijacking
  • http://haacked.com/archive/2009/06/25/json-
    hijacking.aspx
  • - With [HttpPost], returning arrays is allowed.
8) Performance Tips

  • Test the application performance. (Fiddler, YSlow)
  • Optimise /compress your images
  • Minify your scripts and CSS




  Let’s see come code
9) Productivity Tips


  •   Use "Nuget" packages that help with productivity.
  •   ELMAH
  •   MvcScafolding
  •   Create you own nuget packages




  Let’s see come code
Tips
1) ASP.NET is still has the power of ASP.NET

  • You can extend using HttpModules, HttpHandlers
  • You can use HttpCaching




  Let’s see come code
2) Think about globalization from the beginning

  • Make you application support globalisation if its going to
    be on the internet.
  • Don’t forget to make accessibility
     – http://plugins.jquery.com/project/KeyTips
ASP.NET 4.0 Preview
ASP.NET 4.0 Preview



• PageInspector
• Nuget (Enabling MSBuild and Continuous Integration
  environments)
• Mobile phone support improvements
• HTML5 support
• Easier deployment + minification (Including cloud
  deployment)
• Asynchronous / Await
• Tooling (Page Inspector)
• Web Sockets
New Features in ASP.NET MVC 4 Developer Preview
New Features in ASP.NET MVC 4 Developer Preview
Q&A
REFERENCES




• http://www.asp.net/mvc
• http://www.asp.net/vnext/whats-new

• http://haacked.com (Phil Haack)
• http://blog.stevensanderson.com
• http://hanselman.com

• http://orchardproject.net

Weitere ähnliche Inhalte

Was ist angesagt?

ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentationivpol
 
What's new in Visual Studio 2013 & TFS 2013
What's new in Visual Studio 2013 & TFS 2013What's new in Visual Studio 2013 & TFS 2013
What's new in Visual Studio 2013 & TFS 2013Danijel Malik
 
Asp.net c# MVC-5 Training-Day-1 of Day-9
Asp.net c# MVC-5 Training-Day-1 of Day-9Asp.net c# MVC-5 Training-Day-1 of Day-9
Asp.net c# MVC-5 Training-Day-1 of Day-9AHM Pervej Kabir
 
Develop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val KarpovDevelop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val KarpovMongoDB
 
What's new in asp.net mvc 4
What's new in asp.net mvc 4What's new in asp.net mvc 4
What's new in asp.net mvc 4Simone Chiaretta
 
ASP.Net MVC ile Web Uygulamaları -5(Logger)
ASP.Net MVC ile Web Uygulamaları -5(Logger)ASP.Net MVC ile Web Uygulamaları -5(Logger)
ASP.Net MVC ile Web Uygulamaları -5(Logger)İbrahim ATAY
 
ASP .NET MVC
ASP .NET MVC ASP .NET MVC
ASP .NET MVC eldorina
 
Asp.net MVC training session
Asp.net MVC training sessionAsp.net MVC training session
Asp.net MVC training sessionHrichi Mohamed
 
Discuss About ASP.NET MVC 6 and ASP.NET MVC 5
Discuss About ASP.NET MVC 6 and ASP.NET MVC 5Discuss About ASP.NET MVC 6 and ASP.NET MVC 5
Discuss About ASP.NET MVC 6 and ASP.NET MVC 5Aaron Jacobson
 
Codeigniter Training Part3
Codeigniter Training Part3Codeigniter Training Part3
Codeigniter Training Part3Weerayut Hongsa
 
Full stack web development with c# and web assembly - Blazor.Net
Full stack web development with c# and web assembly - Blazor.NetFull stack web development with c# and web assembly - Blazor.Net
Full stack web development with c# and web assembly - Blazor.NetRuwantha Ratnayake
 
ASP.NET MVC 3 in area of Javascript and Ajax improvement
ASP.NET MVC 3 in area of Javascript and Ajax improvementASP.NET MVC 3 in area of Javascript and Ajax improvement
ASP.NET MVC 3 in area of Javascript and Ajax improvementSuthep Sangvirotjanaphat
 
TDD with ASP.NET MVC 1.0
TDD with ASP.NET MVC 1.0TDD with ASP.NET MVC 1.0
TDD with ASP.NET MVC 1.0Shiju Varghese
 
Whys and Hows of Automation
Whys and Hows of AutomationWhys and Hows of Automation
Whys and Hows of AutomationvodQA
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCKhaled Musaied
 

Was ist angesagt? (20)

ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
What's new in Visual Studio 2013 & TFS 2013
What's new in Visual Studio 2013 & TFS 2013What's new in Visual Studio 2013 & TFS 2013
What's new in Visual Studio 2013 & TFS 2013
 
Asp.net c# MVC-5 Training-Day-1 of Day-9
Asp.net c# MVC-5 Training-Day-1 of Day-9Asp.net c# MVC-5 Training-Day-1 of Day-9
Asp.net c# MVC-5 Training-Day-1 of Day-9
 
Develop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val KarpovDevelop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val Karpov
 
What's new in asp.net mvc 4
What's new in asp.net mvc 4What's new in asp.net mvc 4
What's new in asp.net mvc 4
 
ASP.Net MVC ile Web Uygulamaları -5(Logger)
ASP.Net MVC ile Web Uygulamaları -5(Logger)ASP.Net MVC ile Web Uygulamaları -5(Logger)
ASP.Net MVC ile Web Uygulamaları -5(Logger)
 
ASP.NET MVC overview
ASP.NET MVC overviewASP.NET MVC overview
ASP.NET MVC overview
 
ASP .NET MVC
ASP .NET MVC ASP .NET MVC
ASP .NET MVC
 
Asp.net MVC training session
Asp.net MVC training sessionAsp.net MVC training session
Asp.net MVC training session
 
Discuss About ASP.NET MVC 6 and ASP.NET MVC 5
Discuss About ASP.NET MVC 6 and ASP.NET MVC 5Discuss About ASP.NET MVC 6 and ASP.NET MVC 5
Discuss About ASP.NET MVC 6 and ASP.NET MVC 5
 
Codeigniter Training Part3
Codeigniter Training Part3Codeigniter Training Part3
Codeigniter Training Part3
 
Full stack web development with c# and web assembly - Blazor.Net
Full stack web development with c# and web assembly - Blazor.NetFull stack web development with c# and web assembly - Blazor.Net
Full stack web development with c# and web assembly - Blazor.Net
 
ASP.NET MVC 3 in area of Javascript and Ajax improvement
ASP.NET MVC 3 in area of Javascript and Ajax improvementASP.NET MVC 3 in area of Javascript and Ajax improvement
ASP.NET MVC 3 in area of Javascript and Ajax improvement
 
Kentico and MVC
Kentico and MVCKentico and MVC
Kentico and MVC
 
Knockout Introduction
Knockout IntroductionKnockout Introduction
Knockout Introduction
 
Module2
Module2Module2
Module2
 
Angular
AngularAngular
Angular
 
TDD with ASP.NET MVC 1.0
TDD with ASP.NET MVC 1.0TDD with ASP.NET MVC 1.0
TDD with ASP.NET MVC 1.0
 
Whys and Hows of Automation
Whys and Hows of AutomationWhys and Hows of Automation
Whys and Hows of Automation
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 

Andere mochten auch

Getting Started with ASP.NET MVC
Getting Started with ASP.NET MVCGetting Started with ASP.NET MVC
Getting Started with ASP.NET MVCshobokshi
 
Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6Ido Flatow
 
ASP.NET MVC Performance
ASP.NET MVC PerformanceASP.NET MVC Performance
ASP.NET MVC Performancerudib
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC PresentationVolkan Uzun
 

Andere mochten auch (6)

Getting Started with ASP.NET MVC
Getting Started with ASP.NET MVCGetting Started with ASP.NET MVC
Getting Started with ASP.NET MVC
 
Asp.Net MVC Intro
Asp.Net MVC IntroAsp.Net MVC Intro
Asp.Net MVC Intro
 
Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6
 
ASP.NET MVC Performance
ASP.NET MVC PerformanceASP.NET MVC Performance
ASP.NET MVC Performance
 
Model View Controller (MVC)
Model View Controller (MVC)Model View Controller (MVC)
Model View Controller (MVC)
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 

Ähnlich wie ASP.NET MVC Best Practices Under 40 Characters

Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2Long Nguyen
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2divzi1913
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
 
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
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCSirwan Afifi
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework Yakov Fain
 
What is ASP.NET MVC
What is ASP.NET MVCWhat is ASP.NET MVC
What is ASP.NET MVCBrad Oyler
 
Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC  Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC vipin kumar
 
A Smooth Transition to HTML5 Using MVVM
A Smooth Transition to HTML5 Using MVVMA Smooth Transition to HTML5 Using MVVM
A Smooth Transition to HTML5 Using MVVMChris Bannon
 
Asp.NETZERO - A Workshop Presentation by Citytech Software
Asp.NETZERO - A Workshop Presentation by Citytech SoftwareAsp.NETZERO - A Workshop Presentation by Citytech Software
Asp.NETZERO - A Workshop Presentation by Citytech SoftwareRitwik Das
 
DotNet 5.1Years Experience
DotNet 5.1Years ExperienceDotNet 5.1Years Experience
DotNet 5.1Years Experiencechandra sekhar
 
Code igniter overview
Code igniter overviewCode igniter overview
Code igniter overviewumesh patil
 
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Reviewnetc2012
 
Refactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test AutomationRefactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test AutomationStephen Fuqua
 

Ähnlich wie ASP.NET MVC Best Practices Under 40 Characters (20)

Asp 1a-aspnetmvc
Asp 1a-aspnetmvcAsp 1a-aspnetmvc
Asp 1a-aspnetmvc
 
Aspnetmvc 1
Aspnetmvc 1Aspnetmvc 1
Aspnetmvc 1
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
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
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
 
What is ASP.NET MVC
What is ASP.NET MVCWhat is ASP.NET MVC
What is ASP.NET MVC
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
 
Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC  Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC
 
A Smooth Transition to HTML5 Using MVVM
A Smooth Transition to HTML5 Using MVVMA Smooth Transition to HTML5 Using MVVM
A Smooth Transition to HTML5 Using MVVM
 
Angularjs
AngularjsAngularjs
Angularjs
 
Asp.NETZERO - A Workshop Presentation by Citytech Software
Asp.NETZERO - A Workshop Presentation by Citytech SoftwareAsp.NETZERO - A Workshop Presentation by Citytech Software
Asp.NETZERO - A Workshop Presentation by Citytech Software
 
DotNet 5.1Years Experience
DotNet 5.1Years ExperienceDotNet 5.1Years Experience
DotNet 5.1Years Experience
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
Code igniter overview
Code igniter overviewCode igniter overview
Code igniter overview
 
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Review
 
Refactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test AutomationRefactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test Automation
 

Kürzlich hochgeladen

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Kürzlich hochgeladen (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

ASP.NET MVC Best Practices Under 40 Characters

  • 1. ASP.NET MVC [TITLE] Best Practices
  • 2. WHO’S THIS GUY • Malisa Ncube • Software Engineer at Infectious Diseases Institute (Uganda) • Blogger – http://geekswithblogs.net/malisancube • Follow me on Twitter handle - @malisancube • My email is dev@malisancube.com • Leader of Uganda .NET Usergroup #MSOpenDoor • Urban Artist • High sense of humor
  • 3. AGENDA • ASP.NET MVC Best Practices • A bit of ASP.NET MVC 4 Preview • We’ll see • Conclusion • Q&A
  • 5. What is ASP.NET MVC? • Model: The model contains the core information for an application. This includes the data and validation rules as well as data access and aggregation logic. • View: The view encapsulates the presentation of the application, and in ASP.NET this is typically the HTML markup. • Controller: The controller contains the control-flow logic. It interacts with the Model and Views to control the flow of information and execution of the application
  • 6. What is ASP.NET MVC? (Continued) • Opensource – Released under MSL for Pre release components. http://aspnet.codeplex.com • Proven: There are many sites that are using ASP.NET MVC framework and many resources. • Testable: Enables good software development practices.
  • 8. 1) Isolate your layers properly. • Use the ViewModel for transmitting data to the view. They should be simple POCO de-normalised objects. • Use the Domain Model Entities for persistence, validation, Behaviours and complex relationships . Mapping with ViewModel can be done with tools like Automapper.
  • 9. 1) Isolate your layers properly (Continued). • Use Controllers for selecting the view to be shown and not for business logic. • Use the view for displaying Html which will be rendered by the browser. Not for business logic. • Use Services/Repositories for manipulating business objects. Let’s see come code
  • 10. 2) Use the PRG (PostRedirectGet) pattern • Prevent reposts to the form • Issues an HTTP302 with temporary redirect • Watch out for Json redirects. Check the type of requests. • Use proper verbs [HttpPost], [HttpGet] on you controllers
  • 11. 3) Secure site from forgery • Confused deputy problem (A confused deputy is a computer program that is innocently fooled by some other party into misusing its authority) • Prevent (cross site request Forgery)CSRF/XSRF • Prevent (cross site request Forgery)CSRF/XSRF With Ajax • Use Anti-forgery helpers for form posts @Html.AntiForgeryToken and ValidateAntiForgeryTokenAttribute which peeks into Request.Form collection for antiforgery token
  • 12. 4) Make you application testable, maintainable and extensible • Use IoC to make your application testable • Have actual tests for different segments of your application. • You can scaffold the application using NuGet packages like MvcScaffold and include the repository and unit tests. Let’s see come code
  • 13. 5) Write clean code • Use Action Filters for crosscutting concerns. • - They help clean up your code by giving you a declarative approach to programming, similar to Aspect Oriented programming. More specifically Postsharp. • - Handling errors, Authorisation, Tracing. Let’s see come code
  • 14. 6) Use strongly typed views • You may decide to inherit behaviour of all views from a certain base class. • Avoid the ViewBag Let’s see come code
  • 15. 7) JSON endpoints • All JSON endpoints require [HttpPost] to prevent JSON hijacking • http://haacked.com/archive/2009/06/25/json- hijacking.aspx • - With [HttpPost], returning arrays is allowed.
  • 16. 8) Performance Tips • Test the application performance. (Fiddler, YSlow) • Optimise /compress your images • Minify your scripts and CSS Let’s see come code
  • 17. 9) Productivity Tips • Use "Nuget" packages that help with productivity. • ELMAH • MvcScafolding • Create you own nuget packages Let’s see come code
  • 18. Tips
  • 19. 1) ASP.NET is still has the power of ASP.NET • You can extend using HttpModules, HttpHandlers • You can use HttpCaching Let’s see come code
  • 20. 2) Think about globalization from the beginning • Make you application support globalisation if its going to be on the internet. • Don’t forget to make accessibility – http://plugins.jquery.com/project/KeyTips
  • 22. ASP.NET 4.0 Preview • PageInspector • Nuget (Enabling MSBuild and Continuous Integration environments) • Mobile phone support improvements • HTML5 support • Easier deployment + minification (Including cloud deployment) • Asynchronous / Await • Tooling (Page Inspector) • Web Sockets
  • 23. New Features in ASP.NET MVC 4 Developer Preview
  • 24. New Features in ASP.NET MVC 4 Developer Preview
  • 25. Q&A
  • 26. REFERENCES • http://www.asp.net/mvc • http://www.asp.net/vnext/whats-new • http://haacked.com (Phil Haack) • http://blog.stevensanderson.com • http://hanselman.com • http://orchardproject.net