130 likes | 254 Views
INDIA │ 9 th – 11 th January 2011. virtual techdays. ASP.Net MVC. Sundararajan S │ Associate Tech Architect, Aditi Technologies. INDIA │ 9 th – 11 th January 2011. virtual techdays. MVC ASP.Net MVC Hybrid Projects in Asp.Net MVC. S E S S I O N A G E N D A.
E N D
INDIA │ 9th – 11th January 2011 virtual techdays ASP.Net MVC Sundararajan S │ Associate Tech Architect, Aditi Technologies
INDIA │ 9th – 11th January 2011 virtual techdays • MVC • ASP.Net MVC • Hybrid Projects in Asp.Net MVC S E S S I O N A G E N D A
MVC Design pattern • Conery, Hanselman, Haack, Guthrie define it as… • An architectural pattern used to separate an application into three main aspects • Model. Set of classes that represent data and business rules for how data can be changed and manipulated • View.Application’s user interface • Controller. Set of classes that handles communication from user, overall application flow, and application-specific logic
Web forms issues • Web forms don’t support as precise control over “separation of concerns” • Too much of an application ends up in the “code behind” • High level of abstraction • Not as “close to the metal” as some devs want • Web forms are not as well suited for testing • Testing the “code behind” code is difficult • Search engine optimization (SEO) issues • ASP.NET 4.0 addresses this
Model View Controller • Model - Data and Business Rules • View – Presentation layer – Aspx / HTML • Controller – Classes that are responsible for application flow
INDIA │ 9-11 Januarty 2011 virtual techdays Demo – Building a Blog engine in Asp.Net MVC Sundararajan S│ Assoc. Tech Architect, Aditi
ASP.Net MVC Request Processing Architecture Incoming HTTP Request Routing IIS / ASP.Net Matching file on disk Serve the file directly URL Routing Module RouteTable.Routes IRouteHandler IHttpHandler MVCRouteHandler Controller/ Actions Custom controller factory IController ControllerFactory Writes directly to http response ActionMethod Not A ViewResult? Return ActionResult ActionResult.Execute Is A ViewResult?
ASP.Net MVC Request Processing Architecture Views View Engine Custom View Engine WebForm - .Aspx Render View
Hybrid Projects • Add ref to System.Web.Mvc.dll - need to browse for it under C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies • Add ref to System.Web.Routing • Create an Empty MVC Project • Copy the Controllers, Models and Views directories into the Web Forms application • Copy the RegisterRoutes method in Global.asax to the Global.asax in the Web Forms project • Add RegisterRoutes(RouteTable.Routes); to the Application_Start in the Web Forms project • Add using System.Web.MVC and using System.Web.Routing to Global.asax in the Web Forms project
Hybrid projects • Add the following to the <compilation> section of web.config <assemblies> <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </assemblies>
Add the following to the <pages> section of web.config <namespaces> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Routing" /> </namespaces>>
Enable MVC Tooling in Web Form Application • Right-click on project and select unload • Right-click on project and select Edit .csproj • In <ProjectTypeGuids> section add at beginning of list of Guids: {F85E285D-A4E0-4152-9332-AB1D724D3325} • Right-click on project and select reload • Close and reopen solution
Thank you sundararajans@hotmail.com http://tinyurl.com/codeshelve