ASP.NET MVC Zero to Hero
Md. Mahedee Hasan
Microsoft MVP , Visual Studio and Development Technologies
Senior Software Architect, Leadsoft Bangladesh Limited
Trainer, Leads Training and Consulting Limited
Microsoft Community Contributor
Blog: http://mahedee.net
MVP | Software Architect | Trainer | Technical Blogger | MCTS
1
MAHEDEE.NET
2
Introduction to .NET
What is Microsoft .NET?
Another Programming Language?
.NETFramework
Programming Languages
C#, Visual Basic, C++, J# etc.
Markup Languages
HTML, XML etc.
Software development platform
Language neutral
Framework is a basic
or essential
supporting structure
of a system
A
framework
MAHEDEE.NET
3
Introduction to .NET …
Operating System + Hardware
.NET Framework
.NET Application
Narrow view of .NET framework
MAHEDEE.NET
4
ASP.NET
ASP – Active Server Page
Asp.net is an open source server-side web application framework
Designed for Web development to produce dynamic Web pages
Introduced in 1998
Introduction
MAHEDEE.NET
5
ASP.NET
ASP.NET is a new ASP generation.
ASP.NET pages are compiled, which makes them faster
Normally written in VB (Visual Basic) or C# (C sharp).
Introduction …
MAHEDEE.NET
6
ASP.NET
MAHEDEE.NET
7
ASP.NET Web form
Support multiple languages
Improved performance
Control-based, event-driven execution model
More productive
Allows clean cut code
MAHEDEE.NET
8
ASP.NET MVC
MAHEDEE.NET
9
Why .NET?
Easy to learn
Payment is high
High market demand
Develop scalable enterprise application
• Companies looking for .NET developers
• Microsoft
• Google
• CISCO
• Wipro Ltd
• Deloitt
• KPMG
• Marriott International
• Edward Jones
MAHEDEE.NET
10
Why .NET? …
Ref: 1. https://www.youtube.com/watch?v=auErLqIJY2M
MAHEDEE.NET
11
Why .NET? …
MAHEDEE.NET
12
Why .NET? …
.NET developers are one of the highest paid
associates
Yearly Income (India) Rs. 334,959 per year [1]
Ref: 1. https://www.youtube.com/watch?v=auErLqIJY2M
Highest paid .NET developers
ASP.NET MVC Developers IIS Administrator
MAHEDEE.NET
13
Average salary for .NET developers
International Market $45,569 ~ $103,575 per year [1]
Salary in Bangladesh
1. http://www.payscale.com/research/US/Job=.NET_Software_Developer_%2F_Programmer/Salary
2. http://www.salaryexplorer.com/salary-survey.php?loc=18&loctype=1&job=781&jobtype=3
MAHEDEE.NET
14
Job condition in market places
Lots of works
for .NET
developers
Specially for
asp.net
Many Bangladesh
Freelancer work in
.NET platform
.NET developers
are mostly top
rated
Comparatively
large project
MAHEDEE.NET
15
Job Opportunity in Local Market
MAHEDEE.NET
16
Job Opportunity in Local Market …
MAHEDEE.NET
17
Famous web application developed by asp.net
MAHEDEE.NET
18
Future of .NET
Cross Platform Framework
MAHEDEE.NET
19
Future of .NET …
.NET can be used to build
AR/VR application using
unity
Tizen allows .net
developers to build app in
Samsung devices including
Tvs and mobile
MAHEDEE.NET
20
Future of .NET …
MAHEDEE.NET
21
Future of .NET
Is an independent organization
To improve open source software development and
collaboration around the .net framework
MAHEDEE.NET
22
What is MVC?
Application
MAHEDEE.NET
23
What is ASP.NET MVC?
It is Software Architectural pattern
Software Architectural
Pattern
Software
Design Pattern
Run on ASP.NET Framework
MAHEDEE.NET
24
ASP.NET MVC Routing
MAHEDEE.NET
25
ASP.NET MVC Design Principle
Separation of Concern
Convention over configuration
MAHEDEE.NET
26
What is View Engine?
Rendering HTML from views to the browser.
View
Engine
Razor
Traditional
ASPX
Spark
Nhaml
etc
Razor is a markup
language embed with
server-based code
MAHEDEE.NET
27
ASP.NET MVC design goal
MAHEDEE.NET
28
ASP.NET MVC Folder Structure
MAHEDEE.NET
29
Layout
Provide a consistent look and feel on all the
pages of the application
Layout
Configuration
• Page level
• Folder level
• Root level
MAHEDEE.NET
30
Controller
Controllers are classes that handle incoming browser requests
Retrieve data, and then specify view templates and return a
response to the browser
MVC requires the name of all controllers to end with "Controller"
Controller classes inherited from Controller base class
The Controllers Folder contains the controller classes
MAHEDEE.NET
31
Action and Parameters
Action is a public method
The controller defines action methods
Controllers can include as many action methods as needed
Action methods typically have a one-to-one mapping with user
interactions
Can take one or more parameter
MAHEDEE.NET
32
Razor Template
MAHEDEE.NET
33
Introduction to EF
ORM often reduces the amount of code that
needs to be written
MAHEDEE.NET
34
Introduction to EF …
MAHEDEE.NET
36
EF Development Approach
MAHEDEE.NET
37
Annotation
Annotation is a configuration option of the domain class
Key
ForeignKey
NotMapped
StringLength
Timestamp
ConcurrencyCheck
Table
Index
Required
MinLength
MaxLength
Database Schema
related Attributes
Validation Attributes
Identity and Security
MAHEDEE.NET
38
MAHEDEE.NET
39
Authentication
MAHEDEE.NET
40
No Authentication
All anonymous users
MAHEDEE.NET
41
Individual Users Accounts
Forms Authentication
Can also enable Microsoft, Google, Facebook, Twitter
MAHEDEE.NET
42
Organizational Accounts
Active directory services (Azure, Office 365, Local)
MAHEDEE.NET
43
Windows Authentication
Intranet – no anonymous users
Performance tuning and
scalability improvement tips!!
MAHEDEE.NET
45
• How affect in performance?
– Create pdb (program database – uses for debugging) files which
creates extra overhead.
– For this reason you may face timeout problem.
• Best Practice
– Always prepare release in release mode.
MAHEDEE.NET
46
Prepare release with release mode
• By default debug=”true” when you create a web application.
• It is necessary to set debug=”true” in development
environment.
• How affect in performance?
– If you set debug = “true”, application requires the pdb
information to be inserted into the file
– So results in a comparatively larger file and hence processing will
be slow.
MAHEDEE.NET
47
In Web.Config, Set debug=”false”
• Best Practice
– In deployment server, set debug = “false” in web.config
<system.web>
<compilation debug="false" targetFramework="4.5.1" />
</system.web>
MAHEDEE.NET
48
In Web.Config, Set debug=”false”
• Trace the application to monitor the executions of
application or a pages
• Uses for diagnostic purpose
• How affect in performance?
– Loaded extra information to the pages which degrades
performances.
MAHEDEE.NET
49
Turn off Tracing unless until required
• Best Practice
– Always set trace enabled = “false” unless or until you required to
monitor a page’s executions
<system.web>
<trace enabled="true" pageOutput="true" requestLimit="10"
localOnly="false" mostRecent="true" traceMode="SortByTime"/>
</system.web>
MAHEDEE.NET
50
Turn off Tracing unless until required
• Though, ASP.NET manages session state by default, we must
pay attention of session memory management.
• How affect in performance?
– When you store your data in in-process or on a state server or in
a SQL Database, it requires memory.
– It is also time consuming when you store or retrieve data in-
process or state server or SQL server.
MAHEDEE.NET
51
Carefully manage session state
• Best Practice
– If your page is static, it is recommended not to use session state.
In such cases where you don’t need to use session state, disable it
on your web form using the following directive:
<@%Page EnableSessionState="false"%>
– In case you use the session state only to retrieve data and not to
update, make the session state read-only using the following
directive.
<@%Page EnableSessionState ="ReadOnly"%>
– Consider carefully whether there is a need of the state server or
SQL Server mode.
MAHEDEE.NET
52
Carefully manage session state …
• Best Practice
– SQL Server session mode provides lower performance than state
server mode.
– Try to avoid keeping object in session. Since it requires serializing
then de-serializing which affected in performance.
– Use client-side state management than server side.
MAHEDEE.NET
53
Carefully manage session state …
• View State provides page level state management
• As long as the user is on the current page, state is available
and the user redirects to the next page and the current page
state is lost
• View State can store any type of data because it is object
type but it is preferable not to store a complex type of data
due to the need for serialization and deserialization on each
post back
MAHEDEE.NET
54
Disable View State of a page if not required
• How affect in performance?
– It increases the total payload of a page when submitted and
when serving request.
– Serialization and deserialization of the data is required when
submitting data and gets requested data.
• Best Practice
– Pages that do not have any server postback events can have the
view state turned off.
– The default behaviour of the View State property is enabled, but
if you don’t need it, you can turn it off at the control or page
level.
<%@ Page EnableViewState="false" %>
MAHEDEE.NET
55
Disable View State of a page if not required
• Finally block executes whether any exception occurs or not.
• How affect in performance?
– Sometimes application occupy resources where as it doesn’t
need it.
• Best Practice
– Always use a finally block to release resources like closing
database connections, closing files, disposing objects etc.
MAHEDEE.NET
56
Use finally block to release resources
• To show huge number of data in gridview, we cannot think
general way because it takes huge time to load.
• Best Practice
– To load grid view faster take advantages of paging, it shows small
subsets of data at a time.
– JQGrid is faster than asp.net grid view because it does
everything in client side.
MAHEDEE.NET
57
Use paging in grid view
• How affect in performance?
– The uses of web server controls increase the response time.
– Web server controls go to the server executes all of its life cycle
and then rendered on the client side.
• Best Practice
– Don’t use server control unless until required.
– Use HTML elements where suited.
MAHEDEE.NET
58
Minimizes number of web server control
• My blog site: http://mahedee.net
• TechNet Profile:
https://social.technet.microsoft.com/profile/mahede
e/
• Github Profile: https://github.com/mahedee
• Slide Share http://www.slideshare.net/mahedee19
MAHEDEE.NET
59
Q&A
• Email: mahedee.hasan@gmail.com;
Mahedee_hasan@leads-bd.com
• Tag me in facebook group post
• https://www.facebook.com/groups/mstech.bd
• https://www.facebook.com/groups/techshareonline/
MAHEDEE.NET
60
Q&A
• Me in Facebook:
https://facebook.com/mahedee19
• Me in Linkedin:
https://www.linkedin.com/in/mahedee
MAHEDEE.NET
61
Q&A
62

ASP.NET MVC Zero to Hero

  • 1.
    ASP.NET MVC Zeroto Hero Md. Mahedee Hasan Microsoft MVP , Visual Studio and Development Technologies Senior Software Architect, Leadsoft Bangladesh Limited Trainer, Leads Training and Consulting Limited Microsoft Community Contributor Blog: http://mahedee.net MVP | Software Architect | Trainer | Technical Blogger | MCTS 1
  • 2.
    MAHEDEE.NET 2 Introduction to .NET Whatis Microsoft .NET? Another Programming Language? .NETFramework Programming Languages C#, Visual Basic, C++, J# etc. Markup Languages HTML, XML etc. Software development platform Language neutral Framework is a basic or essential supporting structure of a system A framework
  • 3.
    MAHEDEE.NET 3 Introduction to .NET… Operating System + Hardware .NET Framework .NET Application Narrow view of .NET framework
  • 4.
    MAHEDEE.NET 4 ASP.NET ASP – ActiveServer Page Asp.net is an open source server-side web application framework Designed for Web development to produce dynamic Web pages Introduced in 1998 Introduction
  • 5.
    MAHEDEE.NET 5 ASP.NET ASP.NET is anew ASP generation. ASP.NET pages are compiled, which makes them faster Normally written in VB (Visual Basic) or C# (C sharp). Introduction …
  • 6.
  • 7.
    MAHEDEE.NET 7 ASP.NET Web form Supportmultiple languages Improved performance Control-based, event-driven execution model More productive Allows clean cut code
  • 8.
  • 9.
    MAHEDEE.NET 9 Why .NET? Easy tolearn Payment is high High market demand Develop scalable enterprise application
  • 10.
    • Companies lookingfor .NET developers • Microsoft • Google • CISCO • Wipro Ltd • Deloitt • KPMG • Marriott International • Edward Jones MAHEDEE.NET 10 Why .NET? … Ref: 1. https://www.youtube.com/watch?v=auErLqIJY2M
  • 11.
  • 12.
    MAHEDEE.NET 12 Why .NET? … .NETdevelopers are one of the highest paid associates Yearly Income (India) Rs. 334,959 per year [1] Ref: 1. https://www.youtube.com/watch?v=auErLqIJY2M Highest paid .NET developers ASP.NET MVC Developers IIS Administrator
  • 13.
    MAHEDEE.NET 13 Average salary for.NET developers International Market $45,569 ~ $103,575 per year [1] Salary in Bangladesh 1. http://www.payscale.com/research/US/Job=.NET_Software_Developer_%2F_Programmer/Salary 2. http://www.salaryexplorer.com/salary-survey.php?loc=18&loctype=1&job=781&jobtype=3
  • 14.
    MAHEDEE.NET 14 Job condition inmarket places Lots of works for .NET developers Specially for asp.net Many Bangladesh Freelancer work in .NET platform .NET developers are mostly top rated Comparatively large project
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
    MAHEDEE.NET 19 Future of .NET… .NET can be used to build AR/VR application using unity Tizen allows .net developers to build app in Samsung devices including Tvs and mobile
  • 20.
  • 21.
    MAHEDEE.NET 21 Future of .NET Isan independent organization To improve open source software development and collaboration around the .net framework
  • 22.
  • 23.
    MAHEDEE.NET 23 What is ASP.NETMVC? It is Software Architectural pattern Software Architectural Pattern Software Design Pattern Run on ASP.NET Framework
  • 24.
  • 25.
    MAHEDEE.NET 25 ASP.NET MVC DesignPrinciple Separation of Concern Convention over configuration
  • 26.
    MAHEDEE.NET 26 What is ViewEngine? Rendering HTML from views to the browser. View Engine Razor Traditional ASPX Spark Nhaml etc Razor is a markup language embed with server-based code
  • 27.
  • 28.
  • 29.
    MAHEDEE.NET 29 Layout Provide a consistentlook and feel on all the pages of the application Layout Configuration • Page level • Folder level • Root level
  • 30.
    MAHEDEE.NET 30 Controller Controllers are classesthat handle incoming browser requests Retrieve data, and then specify view templates and return a response to the browser MVC requires the name of all controllers to end with "Controller" Controller classes inherited from Controller base class The Controllers Folder contains the controller classes
  • 31.
    MAHEDEE.NET 31 Action and Parameters Actionis a public method The controller defines action methods Controllers can include as many action methods as needed Action methods typically have a one-to-one mapping with user interactions Can take one or more parameter
  • 32.
  • 33.
    MAHEDEE.NET 33 Introduction to EF ORMoften reduces the amount of code that needs to be written
  • 34.
  • 35.
  • 36.
    MAHEDEE.NET 37 Annotation Annotation is aconfiguration option of the domain class Key ForeignKey NotMapped StringLength Timestamp ConcurrencyCheck Table Index Required MinLength MaxLength Database Schema related Attributes Validation Attributes
  • 37.
  • 38.
  • 39.
  • 40.
    MAHEDEE.NET 41 Individual Users Accounts FormsAuthentication Can also enable Microsoft, Google, Facebook, Twitter
  • 41.
  • 42.
  • 43.
    Performance tuning and scalabilityimprovement tips!! MAHEDEE.NET 45
  • 44.
    • How affectin performance? – Create pdb (program database – uses for debugging) files which creates extra overhead. – For this reason you may face timeout problem. • Best Practice – Always prepare release in release mode. MAHEDEE.NET 46 Prepare release with release mode
  • 45.
    • By defaultdebug=”true” when you create a web application. • It is necessary to set debug=”true” in development environment. • How affect in performance? – If you set debug = “true”, application requires the pdb information to be inserted into the file – So results in a comparatively larger file and hence processing will be slow. MAHEDEE.NET 47 In Web.Config, Set debug=”false”
  • 46.
    • Best Practice –In deployment server, set debug = “false” in web.config <system.web> <compilation debug="false" targetFramework="4.5.1" /> </system.web> MAHEDEE.NET 48 In Web.Config, Set debug=”false”
  • 47.
    • Trace theapplication to monitor the executions of application or a pages • Uses for diagnostic purpose • How affect in performance? – Loaded extra information to the pages which degrades performances. MAHEDEE.NET 49 Turn off Tracing unless until required
  • 48.
    • Best Practice –Always set trace enabled = “false” unless or until you required to monitor a page’s executions <system.web> <trace enabled="true" pageOutput="true" requestLimit="10" localOnly="false" mostRecent="true" traceMode="SortByTime"/> </system.web> MAHEDEE.NET 50 Turn off Tracing unless until required
  • 49.
    • Though, ASP.NETmanages session state by default, we must pay attention of session memory management. • How affect in performance? – When you store your data in in-process or on a state server or in a SQL Database, it requires memory. – It is also time consuming when you store or retrieve data in- process or state server or SQL server. MAHEDEE.NET 51 Carefully manage session state
  • 50.
    • Best Practice –If your page is static, it is recommended not to use session state. In such cases where you don’t need to use session state, disable it on your web form using the following directive: <@%Page EnableSessionState="false"%> – In case you use the session state only to retrieve data and not to update, make the session state read-only using the following directive. <@%Page EnableSessionState ="ReadOnly"%> – Consider carefully whether there is a need of the state server or SQL Server mode. MAHEDEE.NET 52 Carefully manage session state …
  • 51.
    • Best Practice –SQL Server session mode provides lower performance than state server mode. – Try to avoid keeping object in session. Since it requires serializing then de-serializing which affected in performance. – Use client-side state management than server side. MAHEDEE.NET 53 Carefully manage session state …
  • 52.
    • View Stateprovides page level state management • As long as the user is on the current page, state is available and the user redirects to the next page and the current page state is lost • View State can store any type of data because it is object type but it is preferable not to store a complex type of data due to the need for serialization and deserialization on each post back MAHEDEE.NET 54 Disable View State of a page if not required
  • 53.
    • How affectin performance? – It increases the total payload of a page when submitted and when serving request. – Serialization and deserialization of the data is required when submitting data and gets requested data. • Best Practice – Pages that do not have any server postback events can have the view state turned off. – The default behaviour of the View State property is enabled, but if you don’t need it, you can turn it off at the control or page level. <%@ Page EnableViewState="false" %> MAHEDEE.NET 55 Disable View State of a page if not required
  • 54.
    • Finally blockexecutes whether any exception occurs or not. • How affect in performance? – Sometimes application occupy resources where as it doesn’t need it. • Best Practice – Always use a finally block to release resources like closing database connections, closing files, disposing objects etc. MAHEDEE.NET 56 Use finally block to release resources
  • 55.
    • To showhuge number of data in gridview, we cannot think general way because it takes huge time to load. • Best Practice – To load grid view faster take advantages of paging, it shows small subsets of data at a time. – JQGrid is faster than asp.net grid view because it does everything in client side. MAHEDEE.NET 57 Use paging in grid view
  • 56.
    • How affectin performance? – The uses of web server controls increase the response time. – Web server controls go to the server executes all of its life cycle and then rendered on the client side. • Best Practice – Don’t use server control unless until required. – Use HTML elements where suited. MAHEDEE.NET 58 Minimizes number of web server control
  • 57.
    • My blogsite: http://mahedee.net • TechNet Profile: https://social.technet.microsoft.com/profile/mahede e/ • Github Profile: https://github.com/mahedee • Slide Share http://www.slideshare.net/mahedee19 MAHEDEE.NET 59 Q&A
  • 58.
    • Email: mahedee.hasan@gmail.com; Mahedee_hasan@leads-bd.com •Tag me in facebook group post • https://www.facebook.com/groups/mstech.bd • https://www.facebook.com/groups/techshareonline/ MAHEDEE.NET 60 Q&A
  • 59.
    • Me inFacebook: https://facebook.com/mahedee19 • Me in Linkedin: https://www.linkedin.com/in/mahedee MAHEDEE.NET 61 Q&A
  • 60.