ASP.NET MVC Best practices

16
Hattan Shobokshi ASP.NET MVC Best Practices

Transcript of ASP.NET MVC Best practices

Page 1: ASP.NET MVC Best practices

Hattan Shobokshi

ASP.NET MVC Best Practices

Page 2: ASP.NET MVC Best practices

*Housekeeping

*Stuttering is a communication disorder involving disruptions, or “disfluencies,” in a person’s speech.

*Across all cultures, roughly 1% of people currently has a stuttering disorder.

*http://westutter.org/

Page 3: ASP.NET MVC Best practices

Who am I?

Hattan ShobokshiSenior Software Engineer

[email protected]

http://speakerrate.com/hattanhttp://www.slideshare.net/

shobokshi

Page 4: ASP.NET MVC Best practices

Goals for this talk

* Look at Examples of BAD CODE

* PRG Pattern

* Load JavaScript files from CDN

* Do not Include view formatting in the controller

* T4 Templates

* Custom View & Controller Templates

* Diagnostic Tools

* Telerik Grid Control

Page 5: ASP.NET MVC Best practices

PRG Pattern

*HTTP POST

*Redirect

*HTTP GET

*The prg pattern is used to ensure that the intended modification of data only happens once.

Page 6: ASP.NET MVC Best practices

Microsoft Ajax Content Delivery

Network

*Content Delivery Network

* Improve Application Performance

*Reuse Javascript files Cached by different domains

*Available Content Files:

* jQuery

* jQuery Validation

* jQuery UI

*Ajax Control Toolkit

*ASP.NET Ajax

*ASP.NET MVC JavaScript Files

*http://www.asp.net/ajaxlibrary/cdn.ashx

<script src='http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.min.js' type='text/javascript'></script>

Page 7: ASP.NET MVC Best practices

*T4 : Text Template Transformation Toolkit

* Code Generation Tool

* Built into Visual Studio (2008 and 2010)

* .tt File Extension

* No syntax highlighting by default

* Clarius Visual T4 Add-on http://www.visualt4.com/

* Tip: Windows 7/Vista unblock zip file, unblock individual files

* More informationhttp://www.olegsych.com/2007/12/text-template-transformation-toolkit/

Page 9: ASP.NET MVC Best practices

T4MVC

*<%= Html.ActionLink(“New Dinner", “Create", "Dinners")%>

*<%= Html.ActionLink(" New Dinner", MVC.Dinners.Create())%>

*<img src="/Content/nerd.jpg" />

*<img src="<%= Links.Content.nerd_jpg %>" />

http://mvccontrib.codeplex.com/wikipage?title=T4MVC_doc

Page 10: ASP.NET MVC Best practices

T4 Code Templates

*Custom Tooling

*Customize Default View Templates

*Add new View Templates

*Customize Controller Template

*T4 Templates

*~\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 2

*~\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\VisualBasic\Web\MVC 2

Page 11: ASP.NET MVC Best practices

Route Debugger

*Add Reference to Dll

*Enable route debugging with 1 line of code

RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);

*http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

Page 12: ASP.NET MVC Best practices

MVC Diagnostics

*Environment Information

*MVC Assembly Version

*Referenced Assembly Information

*Web Forms page, not an mvc page

*http://bradwilson.typepad.com/blog/2010/03/diagnosing-aspnet-mvc-problems.html

Page 13: ASP.NET MVC Best practices

*Telerik Grid Control

*http://demos.telerik.com/aspnet-mvc/

* Grid Control

*Out of the box support for Sorting, Filtering

*Out of the box paging support

*Out of the box ajax support

*Very little javascript you have to write!

Page 14: ASP.NET MVC Best practices

What did we just talk about?

* Look at Examples of BAD CODE

* PRG Pattern

* Load JavaScript files from CDN

* Do not Include view formatting in the controller

* T4 Templates

* Custom View & Controller Templates

* Diagnostic Tools

* Telerik Grid Control

Page 15: ASP.NET MVC Best practices

Contact Information

*Email: [email protected]

*www.hattanshobokshi.com

Page 16: ASP.NET MVC Best practices

The End

Thank you!