Controllers.

Slides:



Advertisements
Similar presentations
INTRODUCTION TO ASP.NET MVC AND EXAMPLE WALKTHROUGH RAJAT ARYA EFECS - OIM DAWG – 4/21/2009 ASP.NET MVC.
Advertisements

Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
Introduction to MVC Action Methods, Edit View, and a Search Feature NTPCUG Dr. Tom Perkins.
 The Citrix Application Firewall prevents security breaches, data loss, and possible unauthorized modifications to Web sites that access sensitive business.
1.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
It’s always better live. MSDN Events Security Best Practices Part 2 of 2 Reducing Vulnerabilities using Visual Studio 2008.
06 | Implementing Web APIs Jon Galloway | Tech Evangelist Christopher Harrison | Head Geek.
Microsoft ® Official Course Interacting with the Search Service Microsoft SharePoint 2013 SharePoint Practice.
1 Chapter 20 — Creating Web Projects Microsoft Visual Basic.NET, Introduction to Programming.
Virtual techdays INDIA │ November 2010 ASP.Net MVC Deep Dive Sundararajan S │ Associate Tech Architect, Aditi Technologies.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
UNIT-V The MVC architecture and Struts Framework.
Delivering Excellence in Software Engineering ® EPAM Systems. All rights reserved. ASP.NET Authentication.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
JavaScript & jQuery the missing manual Chapter 11
Server-side Scripting Powering the webs favourite services.
ASP.NET Web API Udaiappa Ramachandran NHDN-Nashua.NET/Cloud Computing UG Lead Blog:
ASP.NET and Model View Control Jesper Tørresø ITNET2 F08.
Standalone Java Application vs. Java Web Application
Introduction to ASP.NET MVC Information for this presentation was taken from Pluralsight Building Applications with ASP.NET MVC 4.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Introduction to Entity Framework Part 2 CRUD Scaffolding Tom Perkins NTPCUG.
1.NET Web Forms Web Services © 2002 by Jerry Post.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
Building Secure Web Applications With ASP.Net MVC.
BIT 286: Web Applications Lecture 10 : Thursday, February 5, 2015 ASP.Net Form Submission.
Module 7: Advanced Application and Web Filtering.
 Registry itself is easy and straightforward in implementation  The objects of registry are actually complicated to store and manage  Objects of Registry.
Forms Collecting Data CSS Class 5. Forms Create a form Add text box Add labels Add check boxes and radio buttons Build a drop-down list Group drop-down.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflow Analysis of Buffer Overflow Attacks.
ICM – API Server & Forms Gary Ratcliffe.
ASP.NET User Controls. User Controls In addition to using Web server controls in your ASP.NET Web pages, you can create your own custom, reusable controls.
CS 160 and CMPE/SE 131 Software Engineering February 9 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
Introduction  “M” “V” “C” stands for “MODEL” “VIEW” “CONTROLLER”. ASP.NET MVC is an architecture to develop ASP.NET web applications in a different manner.
Virtual techdays INDIA │ 9-11 February 2011 SESSION TITLE Kamala Rajan S │ Technical Manager, Marlabs.
Securing Web Applications Lesson 4B / Slide 1 of 34 J2EE Web Components Pre-assessment Questions 1. Identify the correct return type returned by the doStartTag()
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC -
BIT 286: Web Applications ASP.Net MVC. Objectives Applied MVC overview Controllers Intro to Routing Views ‘Convention over configuration’ Layout files.
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Part VI: Mapping URLs.
1 Using MVC 6. MVC vs. ASP Web Forms Both run under ASP.NET Can coexist In Web Forms, browser requests page. xxx.aspx and xxx.aspx.cs on the server Page.
Introduction to MVC Slavomír Moroz. Revision from Previous Lesson o ASP.NET WebForms applications Abstract away HTTP (similar to desktop app development)
19 Copyright © 2008, Oracle. All rights reserved. Security.
Data and tools on the Web have been exposed in a RESTful manner. Taverna provides a custom processor for accessing such services.
Jim Fawcett CSE686 – Internet Programming Spring 2014
Windows Communication Foundation and Web Services
Ask the Experts – Building Login-Based Sites in AEM
ASP.NET Forms.
An introduction to ASP.Net with MVC Nischal S
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
Building Web Applications with Microsoft ASP
Jim Fawcett CSE686 – Internet Programming Spring 2012
Section 13 - Integrating with Third Party Tools
Introduction to CodeIgniter (CI)
Introduction to Triggers
Cross-Site Forgery
SharePoint Cloud hosted Apps
04 | Customizing Controllers
…and web frameworks in general
Authorization in Asp.Net Core
Social Media And Global Computing Managing MVC with Custom Models
Customizing Controllers Controllers Customizing කර ගැනීම
Project Management in SharePoint
Project Management in SharePoint
…and web frameworks in general
ASP.NET MVC Web Development
Mr. Justin “JET” Turner CSCI 3000 – Fall 2016 Section DA MW 4:05-5:20
Chengyu Sun California State University, Los Angeles
Presentation transcript:

Controllers

Taking Control of Controllers Adding Actions Model Binding Filters Vanity URLs Controller Best Practices

Taking Control of Controllers Adding Actions Model Binding Filters Vanity URLs Controller Best Practices

Adding Actions Controllers are classes Actions are methods Creating an action involves adding a method to a class

Action Signature Return Types Parameters ActionResult FileResult JsonResult ViewResult Parameters Normal parameters MCV model binding Parameters in MVC are just normal parameters. Typically, return types are ActionResult or something that inherits from ActionResult.

Controller Method Attributes HttpGet & HttpPost Known as methods or verbs Send a signal from the client to the server Header information that lets user send large amounts of data

Get and Post Create/Update/Delete are typically two step operations Present the form Accept the input Create two actions Form presentation via HttpGet (default) Accept data via HttpPost

Controllers All the controller classes inherit from the base class Controller Has built in helper methods such as View() Parameter to the View method is the data that the view needs Controller method gets the model and combines the model with the view to return public ActionResult Index() { return View(db.Movies.ToList()); }

Default Model Binder Uses the name attribute of input elements Automatically matches parameter names for simple data types Complex objects are mapped by property name Complex properties use dot notation @Html.EditorFor(model => model.Lyrics, …

Controlling Model Binding Imagine the following model Need Create a form to edit everything but the lyrics Challenge Default model binder automatically binds all inbound properties

Solutions Simplest Use the bind attribute to indicate which properties to bind Other solutions Create a view model Create a custom model binder Create a view model with only the SongID, Title, and Length attributes. Creating a custom model binder is possible, but not recommended.

Filters Filters are attributes Goal is to alter execution Decorate controllers and actions Goal is to alter execution MVC contains several built-in filters If you want the filter to be global, put it in the FilterConfig.cs file Sometimes you want to perform logic either before an action method is called or after an action method runs. To support this, ASP.NET MVC provides filters. Filters are custom classes that provide both a declarative and programmatic means to add pre-action and post-action behavior to controller action methods. ASP.NET has several built in filters. For example: Can set up security with filters by decorating an action with a filter

Security Filters Authorize ValidateAntiForgeryToken RequireHttps Control who can access a controller/action Properties Users Roles ValidateAntiForgeryToken Defends against cross-site request forgery Requires anti-forgery token to be added to view RequireHttps Uses SSL Might use Authorize on Create, Edit, and Delete, to automatically redirect you to a login page ValidateAntiForgeryToken - Make sure a form has not been set from a different page

SSL Encrypts traffic and prevents tampering Authenticates server When to use SSL Asking for sensitive information After authentication When in doubt enable SSL http://blog.codinghorror.com/should-all-web-traffic-be-encrypted/

Vanity URL Standard URL Vanity URL Users have no idea what that URL refers to Search engines have no idea what that URL refers to Vanity URL User knows information provided by the page Search engines know information provided by page

MVC Routing Vanity URLs are handled by routing Routing in MVC controls what controller/action is called based on the URL provided Methods for updating routing RouteConfig.cs AttributeRouting

Attribute Routing Attributes control routing/URL RouteAttribute www.mymusicstore.com/Album/Edit/42 Calls the Edit action Passes in the ID parameter ID must be an integer Could use to make the method names more user friendly in the Vanity URL. For example could have the route attribute for the Index method renamed to all: [Route(“Album/All”)]

RoutePrefix Added to controller Adds prefix to all routes Controller is now named Album instead of Albums in the URL route

Controller Design Guidelines High Cohesion Make sure all actions are closely related Low Coupling Controllers should know as little about the rest of the system as possible Simplifies testing and changes Repository pattern Wrap data context calls into another object Controller methods are typically short, 5 to 10 lines of code. There are two ways that the repository can query business entities. It can submit a query object to the client's business logic or it can use methods that specify the business criteria. In the latter case, the repository forms the query on the client's behalf. The repository returns a matching set of entities that satisfy the query. The diagram shows the interactions of the repository with the client and the data source.