390 likes | 1.02k Views
ASP.net MVC in A Web Hosted World. Jeff Ammons. The Atlanta Journal-Constitution Developer/DBA GGMUG.com President Gwinnett, Georgia, Microsoft User Group 2 nd Thursday, 6:30 PM Gwinnett Tech Blog: http://ammonsonline.com/jeffablog. Agenda. Define Hosted Environment Intro To MVC
E N D
Jeff Ammons • The Atlanta Journal-Constitution • Developer/DBA • GGMUG.com • President • Gwinnett, Georgia, Microsoft User Group • 2nd Thursday, 6:30 PM Gwinnett Tech • Blog: http://ammonsonline.com/jeffablog
Agenda • Define Hosted Environment • Intro To MVC • Define Challenges • Explore Strategies
What Is Hosted Environment? • Web • Shared Server • Managed By Hosting Company
What’s Included? • Web Server • File Storage • Database • Bandwidth • Email
Examples • GoDaddy • Hostgator • DiscountASP.net • Bizhostnet.com
Data Persistence Options • MySQL • SQL Server • File Based • XML • JSON
SQL Server • $15/month = Unlimited 200 MB DBs • Good basic set of functionality • Choice of access methods • LINQ To SQL • Entity Framework • ADO • Etc.
Who Is This Environment For? • Start-ups • Non-profit organizations • Personal use
Why Choose A Hosted Env? • Lost cost ($5-$20/month) • Quick Start • Fewer People Required • No hardware to buy • No hardware to maintain • No server room
Challenges • Server Access • Server Options • Server Load • Dude, Where’s My Data? • Dude, Who Can See My Data?
Microsoft vs FOSS:The FOSS Advantage • Lots of FOSS based sites (LAMP) • Lots of FOSS sample code • Zero start-up cost • MS stack seen as ugly and corporate-looking
Microsoft vs FOSS:The Empire Strikes Back • Asp.Net MVC • JQuery supported • OFFICIALLY • Visual Studio • Express Edition • BizSpark • WebsiteSpark • You CAN achieve zero start-up cost • You CAN make good looking sites
What is MVC? • Model • View • Controller
?? • Design Pattern • Microsoft Web Framework
MVC Pattern Model Data + Biz Rules Controller Middle Man/Traffic Cop View Presentation UI
Asp.Net Options SharePoint WebForms MVC ASP.NET
MVC vsWebforms MVC Webforms • No controls • Full control of emitted HTML • Clean HTML emitted • Might take longer but you have total control of look and feel • Separation of Concerns • Easier for tests, TDD • Clean URLs • www.myblog.com/my_story • Lot of controls • Don’t need to do so much HTML • Viewstate makes HTML lovers cry • Quick but often “looks like Microsoft Website” • More tightly coupled • Not so clean URLs • www.myblog.com/blog.aspx?permalink=my_story
Which To Choose? MVC Webforms • Internet Apps • UI is crucial • Attracting user is crucial • Users will leave if it doesn’t look sexy • Internal IT apps • Developer time is crucial • Fill biz need is crucial • Users won’t leave if it doesn’t look sexy None of these statements are absolutes!
Demo Time • Hello, MVC World • jeffaBlogger
How Do You Get MVC To Work In Hosted Env? • Request IIS 7 • Publish Your Project • Include MVC DLL if necessary
Strategies For Success • ActionLink Sucks At Virtual Directories • www.mydomain.com • www.mydomain2.com • /root mydomain.com • /root/mydomain2 mydomain2.com • www.mydomain2.com/mydomain2/my_story
ActionLinkV • You can replace darned near anything in MVC • The source is Open • ActionLinkV replaces ActionLink • Add Helpers Directory • Add files to Helpers • Register in web.config
Cache, Cache, Cache • Thanks to ASP.net plumbing • You just call it differently than webforms • Don’t hit the database if you don’t need to • Set in the CONTROLLER • Set for entire controller • Set for individual methods • Do NOT cache personal info! • Options • Set cache location • Vary by param
Repository Model • Controller interacts with • Interface • Abstract Class • Different implementations • Entity Framework • Linq To Sql • Xml • Mock
Linq To Objects • For small datasets • Query collections of objects • Use object serialization to save to disk • What it wants to be when it grows up • http://research.microsoft.com/en-us/projects/dryad/
What Is LINQ? • Language INtegrated Query • SQL-like language construct for .Net • Joins • Tables • Objects • Both • Aggregation • Selection • Go to Jim Wooley’s session next!
Example LINQ Query var orderedModuleList = from module in itemList.getList() orderby module.Name select module;
LINQ To Lots Of Stuff • LINQ To Entities • LINQ To SQL • LINQ To Objects • LINQ To XML
File System Options • POCO (Built-in .Net Serialization) • XML
Why? Why? Why? • Not ALL apps (or portions of apps) need relational databases • Burn the heretic!!! • SMALL datasets • Lots of Readers/Few Publishers • Blog • Informational site • Personal site • Excessive DB Traffic
Example • Custom ASP.Net Membership Provider • Basic log-on info • Works great with 10-30,000 users • Total DOG with 500,000 users • No calls to DB server • Most start-ups would KILL to get 10,000 users
CSS Themes • Standards Compliant • http://www.freecsstemplates.org/ • Create base class for your controllers • Put link into ViewData • Since it is in the base of all your controllers, all controllers will pass it to the views
Security • HTML Encode as much data as possible • Variety of Javascript attacks • Use AntiForgeryToken helper
Goals For Your Project • Website itself • Web app others can use
Helpful Links • MVC • http://www.asp.net/mVC/ • Blogs • http://weblogs.asp.net/Scottgu/ • http://haacked.com • http://www.hanselminutes.com/ • Sites • http://www.nerddinner.com/ • http://stackoverflow.com/