ASP.NET Core 1.1 MVC for Beginners

Total Page:16

File Type:pdf, Size:1020Kb

ASP.NET Core 1.1 MVC for Beginners ASP.NET Core 1.1 MVC For Beginners How to build a Video Course Website ASP.NET Core 1.1 MVC For Beginners - How to build a Video Course Website Overview .............................................................................................................................. 1 Setup ................................................................................................................................ 2 Other Titles by the Author ............................................................................................... 2 MVC 5 – How to Build a Membership Website (video course) ................................... 2 Store Secret Data in .NET Core Web App with Azure Key Vault (video course) .......... 3 C# for Beginners: The Tactical Guidebook................................................................... 3 ASP.NET MVC 5 – Building a Website: The Tactical Guidebook .................................. 4 Source Code and Bonus Materials................................................................................... 5 Disclaimer – Who Is This Book for? ................................................................................. 5 Rights ............................................................................................................................... 5 About the Author ............................................................................................................ 6 Part 1: ASP.NET Core 1.1 MVC Your First Application ........................................................ 7 1. Your First ASP.NET Core Application ............................................................................... 8 Creating the Solution and Project ................................................................................... 8 The Project Layout and the File System .................................................................... 11 Important Files .......................................................................................................... 12 Compiling the Solution .............................................................................................. 13 The Startup.cs File ..................................................................................................... 14 Adding a Configuration Service ..................................................................................... 15 Creating a Service .......................................................................................................... 18 Example ..................................................................................................................... 18 Adding the Interface .............................................................................................. 19 Adding the HardcodedMessageService Class ........................................................ 20 Configure and Use the HardcodedMessageService Class ..................................... 20 Add and Use the ConfigurationMessageService Class .......................................... 22 Summary ........................................................................................................................ 24 ASP.NET Core 1.1 MVC For Beginners - How to build a Video Course Website 2. Middleware ................................................................................................................... 25 How Does Middleware Work? ...................................................................................... 25 IApplicationBuilder ........................................................................................................ 26 Handling Exceptions .................................................................................................. 28 Serving Up Static Files ................................................................................................... 31 Serving Up Default Files ................................................................................................. 33 Setting Up ASP.NET MVC ............................................................................................... 33 Adding the MVC NuGet Package ............................................................................... 34 Summary ........................................................................................................................ 36 3. MVC Controllers ............................................................................................................ 37 Routing .......................................................................................................................... 38 Convention-Based Routing ........................................................................................ 39 Implement Routing ................................................................................................ 40 Adding Another Controller .................................................................................... 42 Attribute Routing ....................................................................................................... 43 IActionResult ................................................................................................................. 46 Implementing ContentResult .................................................................................... 47 Using a Model Class ................................................................................................... 47 Introduction to Views .................................................................................................... 49 A View with a Data Collection ....................................................................................... 50 Adding a Data Service .................................................................................................... 53 Summary ........................................................................................................................ 57 4. Models ........................................................................................................................... 58 View Model Example ..................................................................................................... 59 Changing the Folder Structure .................................................................................. 59 Adding the View Model ............................................................................................. 59 Using the View Model ............................................................................................... 60 ASP.NET Core 1.1 MVC For Beginners - How to build a Video Course Website Adding a Details View ................................................................................................ 61 Adding a Create View .................................................................................................... 65 Refactoring the Application ....................................................................................... 66 Adding the HTTP GET Create Action and the Create View ........................................ 68 Adding the VideoEditViewModel Class ..................................................................... 70 Adding the HTTP POST Create Action ........................................................................ 71 Data Annotations ........................................................................................................... 76 Preparing the Crate View for Validation ................................................................... 77 Adding Validation to the Create View ................................................................... 77 Validating the Model on the Server .......................................................................... 78 Adding Data Annotations in the Video Entity and the VideoEditViewModel Class .. 79 Summary ........................................................................................................................ 82 5. Entity Framework .......................................................................................................... 83 Installing Entity Framework and User Secrets ............................................................... 83 Adding the VideoDbContext Class ............................................................................. 85 Configuration in the Startup Class ............................................................................. 86 Adding the Initial Migration and Creating the Database ........................................... 88 Adding the SqlVideoData Service Component .............................................................. 90 Implementing the SqlVideoData Service Component Class ...................................... 90 Summary ........................................................................................................................ 93 6. Razor Views ................................................................................................................... 94 Layout Views .................................................................................................................. 94 Adding the _Layout View ........................................................................................... 95 Altering the Content Views ....................................................................................... 95 The _ViewStart file ........................................................................................................ 99 The _ViewImports file
Recommended publications
  • Customizing and Extending IBM Content Navigator
    Front cover Customizing and Extending IBM Content Navigator Understand extension points and customization options Create an action, service, feature, and custom step processor Use widgets in apps, mobile development, and more Wei-Dong Zhu Brett Morris Tomas Barina Rainer Mueller-Maechler Yi Duan Ron Rathgeber Nicole Hughes Jana Saalfeld Marcel Kostal Jian Xin Zhang Chad Lou Jie Zhang ibm.com/redbooks International Technical Support Organization Customizing and Extending IBM Content Navigator May 2014 SG24-8055-01 Note: Before using this information and the product it supports, read the information in “Notices” on page xi. Second Edition (May 2014) This edition applies to Version 2, Release 0, Modification 0 of IBM Content Navigator found in IBM FileNet Content Manager (product number 5724-R81), IBM Content Manager (product number 5724-B19), and IBM Content Manager OnDemand (product number 5724-J33). © Copyright International Business Machines Corporation 2012, 2014. All rights reserved. Note to U.S. Government Users Restricted Rights -- Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Notices . xi Trademarks . xii Preface . xiii Authors . xiv Now you can become a published author, too! . xvii Comments welcome. xvii Stay connected to IBM Redbooks . xviii Summary of changes . xix May 2014, Second Edition . xix Part 1. Introduction . 1 Chapter 1. Extension points and customization options . 3 1.1 Before you begin . 4 1.1.1 IBM Content Navigator terms . 4 1.2 Development options with IBM Content Navigator . 6 1.2.1 Configuring IBM Content Navigator . 6 1.2.2 Implementing the EDS interface . 7 1.2.3 Implementing a plug-in .
    [Show full text]
  • The Effect of Ajax on Performance and Usability in Web Environments
    The effect of Ajax on performance and usability in web environments Y.D.C.N. op ’t Roodt, BICT Date of acceptance: August 31st, 2006 One Year Master Course Software Engineering Thesis Supervisor: Dr. Jurgen Vinju Internship Supervisor: Ir. Koen Kam Company or Institute: Hyves (Startphone Limited) Availability: public domain Universiteit van Amsterdam, Hogeschool van Amsterdam, Vrije Universiteit 2 This page intentionally left blank 3 Table of contents 1 Foreword ................................................................................................... 6 2 Motivation ................................................................................................. 7 2.1 Tasks and sources................................................................................ 7 2.2 Research question ............................................................................... 9 3 Research method ..................................................................................... 10 3.1 On implementation........................................................................... 11 4 Background and context of Ajax .............................................................. 12 4.1 Background....................................................................................... 12 4.2 Rich Internet Applications ................................................................ 12 4.3 JavaScript.......................................................................................... 13 4.4 The XMLHttpRequest object..........................................................
    [Show full text]
  • The Lift Approach
    Science of Computer Programming 102 (2015) 1–19 Contents lists available at ScienceDirect Science of Computer Programming www.elsevier.com/locate/scico Analyzing best practices on Web development frameworks: The lift approach ∗ María del Pilar Salas-Zárate a, Giner Alor-Hernández b, , Rafael Valencia-García a, Lisbeth Rodríguez-Mazahua b, Alejandro Rodríguez-González c,e, José Luis López Cuadrado d a Departamento de Informática y Sistemas, Universidad de Murcia, Campus de Espinardo, 30100 Murcia, Spain b Division of Research and Postgraduate Studies, Instituto Tecnológico de Orizaba, Mexico c Bioinformatics at Centre for Plant Biotechnology and Genomics, Polytechnic University of Madrid, Spain d Computer Science Department, Universidad Carlos III de Madrid, Spain e Department of Engineering, School of Engineering, Universidad Internacional de La Rioja, Spain a r t i c l e i n f oa b s t r a c t Article history: Choosing the Web framework that best fits the requirements is not an easy task for Received 1 October 2013 developers. Several frameworks now exist to develop Web applications, such as Struts, Received in revised form 18 December 2014 JSF, Ruby on Rails, Grails, CakePHP, Django, and Catalyst. However, Lift is a relatively new Accepted 19 December 2014 framework that emerged in 2007 for the Scala programming language and which promises Available online 5 January 2015 a great number of advantages and additional features. Companies such as Siemens© and Keywords: IBM®, as well as social networks such as Twitter® and Foursquare®, have now begun to Best practices develop their applications by using Scala and Lift. Best practices are activities, technical Lift or important issues identified by users in a specific context, and which have rendered Scala excellent service and are expected to achieve similar results in similar situations.
    [Show full text]
  • Presentation Title up to a Maximum of Three Lines Font
    The Script Bowl Featuring Groovy, JRuby, Jython and Scala Raghavan “Rags” N. Srinivas CTO, Technology Evangelism The Script Bowl: Groovy Style Guillaume Laforge VP Technology at G2One, Inc. Groovy Project Manager http://www.g2one.com Guillaume Laforge Groovy Project Manager • Co-author of the Groovy in Action best-seller Manning • JSR-241 Spec Lead, • VP Technology at G2One, Inc. standardizing the Groovy • Professional services around dynamic language in the JCP Groovy and Grails • http://www.g2one.com • Initiator of the Grails web application framework 2008 JavaOneSM Conference | java.sun.com/javaone | 3 Groovy is… An Open Source dynamic language for the Virtual Machine for the Java™ platform (Java Virtual Machine or JVM™ machine) No impedence mismatch with Java™ programming environment • Groovy uses a syntax much like Java programming language • Shares the same object / threading / security model as Java programming language • Uses the same APIs (regex, collections, strings…) • Compiles down to normal Java programming language bytecode Provides native syntax constructs • Lists, maps, regex, ranges Supports closures • Simpler than any proposals for Java programming language! Groovy simplifies the use of many Java programming language APIs • XML, Swing, JDBC™ API, unit testing & mocking, templating … 2008 JavaOneSM Conference | java.sun.com/javaone | 4 The Script Bowl: JRuby Charles Nutter Technical Lead, JRuby JRuby Co-Lead Charles Oliver Nutter Longtime developer of Java application environment (11+ yrs ) Engineer at Sun Microsystems
    [Show full text]
  • Experiencing Software Landscapes Using HCI in Explorviz
    Experiencing Software Landscapes using HCI in ExplorViz Bachelor’s Thesis Matthias Möller September 30, 2017 Kiel University Department of Computer Science Software Engineering Group Advised by: Prof. Dr. Wilhelm Hasselbring M.Sc. Christian Zirkelbach Eidesstattliche Erklärung Hiermit erkläre ich an Eides statt, dass ich die vorliegende Arbeit selbstständig verfasst und keine anderen als die angegebenen Quellen und Hilfsmittel verwendet habe. Kiel, 9. Dezember 2017 iii Abstract The Brain-Computer-Interface (BCI) is an interface receiving the brain’s signals and con- verting them into computer signals. Although the BCI’s importance increased in the last years and most probably will increase further, most people have never heard of this device, because this device has yet not gained much place in our daily life routines, but this could change soon. At the moment portable, low-cost BCIs emerge from the market and open new opportunities in the context of interaction between human and machine, but these low-cost BCIs are mostly untested. Furthermore, there are barely approaches to implement the BCI as additional tool in an already existing software, yet. Our working processes were inspired by gaining informations about the BCI as new possibility for task comprehensions. Therefore, we wanted to implement a BCI’s functional- ity into the software tool ExplorViz. We worked with a low-cost BCI called Emotiv Insight and made in the beginning first experiences with the BCI as new interface. After we had designed our software, we implemented a plugin, which optionally extends ExplorViz by the possibility to use the BCI and, thereby, to use two different thoughts as additional navigation possibilities.
    [Show full text]
  • Olivier BRUCHEZ, Software Engineer / Scala Developer
    Olivier BRUCHEZ, Software Engineer / Scala Developer Nationality: Swiss Lausanne, Switzerland +41 (0)79 783 92 39 [email protected] linkedin.com/in/obruchez github.com/obruchez Professional Experience May 2012 - Software engineer / Scala developer at Metamedia Center, EPFL present Developed and maintained a digital asset management (DAM) database for the Montreux Jazz Digital Project (Scala, Play, Akka, Slick, Elasticsearch, Lift). Some sub-projects I've worked on include: ​ ​ ● Ingestion solution based on Archivematica (Akka, Slick, S3, Google APIs) ​ ● REST API for iPad and web applications (Akka, Elasticsearch, JSON) ​ ● Artist contracts / music rights management and search ● Photo import tool using fuzzy string searching ● Integration with a smart playlist generator ● Various import/export and integrity check tools ● Various audio/video compression/processing tools (ffmpeg, custom algorithms, etc.) ● Integration of various algorithms (perceptual hashes, affinity propagation clustering, etc.) Aug. 2011 - Software engineer / Scala developer at E-mmunizer / Groowin ● Developed a highly scalable web platform based on cutting-edge technology (Scala, Lift, Mar. 2012 ​ Cassandra, PostgreSQL, S3, jQuery) Sep. 2009 - Software engineer / consultant at ELCA Informatique Jul. 2011 Mar. 2011 - Jul. 2011 ● Maintained and tested an unforgeable code printing framework (embedded part), as well as a layout editor for different printers (Python, C#, C++) ​ Sept. 2009 - Feb. 2011 (SIX Card Solutions) ● Developed a web application to allow multiple teams to synchronize their activities during the deployment of a release into the production environment (Java, Google Web Toolkit / GWT) ​ ● Debugged and partially rewrote a risk management (fraud detection) module previously developed by an intern (C++, SQL, large databases) ​ ● Developed and maintained various online/high-availability and offline electronic payment applications using Scrum (agile method), UML, and test-driven development (TDD) (Java, C++, ​ SQL, large databases) Jul.
    [Show full text]
  • A Web Framework for Web Development Using C++ and Qt
    C++ Web Framework: A Web Framework for Web Development using C++ and Qt Herik Lima1;2 and Marcelo Medeiros Eler1 1University of Sao˜ Paulo (EACH-USP), Sao˜ Paulo, SP, Brazil 2XP Inc., Sao˜ Paulo, SP, Brazil Keywords: Web, Framework, Development, C++. Abstract: The entry barrier for web programming may be intimidating even for skilled developers since it usually in- volves dealing with heavy frameworks, libraries and lots of configuration files. Moreover, most web frame- works are based on interpreted languages and complex component interactions, which can hurt performance. Therefore, the purpose of this paper is to introduce a lightweight web framework called C++ Web Framework (CWF). It is easy to configure and combine the high performance of the C++ language, the flexibility of the Qt framework, and a tag library called CSTL (C++ Server Pages Standard Tag Library), which is used to handle dynamic web pages while keeping the presentation and the business layer separated. Preliminary evaluation gives evidence that CWF is easy to use and present good performance. In addition, this framework was used to develop real world applications that support some business operations of two private organizations. 1 INTRODUCTION configuration files; and writing glue code to make multiple layers inter-operate (Vuorimaa et al., 2016). Web Applications have been adopted as the de facto In addition, many web frameworks present poor doc- platform to support business operations of all sort of umentation (Constanzo and Casas, 2016; Constanzo organizations for a long time. This has been even and Casas, 2019). more stimulated by the availability of modern frame- Those peculiar characteristics of web devel- works and tools (Chaubey and Suresh, 2001) along opment environments have many practical conse- side with the growth of technologies related to Soft- quences.
    [Show full text]
  • {DOWNLOAD} the Definitive Guide to Lift : a Scala-Based Web
    THE DEFINITIVE GUIDE TO LIFT : A SCALA-BASED WEB FRAMEWORK PDF, EPUB, EBOOK Marius Danciu | 200 pages | 30 Jul 2009 | Springer-Verlag Berlin and Heidelberg GmbH & Co. KG | 9781430224211 | English | Berlin, Germany The Definitive Guide to Lift : A Scala-based Web Framework PDF Book While many are concerned with building Lift or are build program archetypes, there are two you will probably encounter fairly frequently as a Lift user:. Studying others is a natural way to learn; however, it's as easy to learn bad habits through imitation as it is to acquire good ones. The better way to become HTML-fluent is through a comprehensive reference that covers the language syntax, semantics, and variations in detail and demonstrates the difference between good and bad usage. Learn how to install and use Express. JavaScript is currently disabled, this site works much better if you enable JavaScript in your browser. If you're a decent developer, the app should already be build in your mind. Lift makes it fun to develop because it lets you focus on the interesting parts of coding. The Definitive Guide to AdonisJs also covers how to create a front-end build chain, so that you can use a modern front-end framework, such as React. An archived version of blog. Everyone I know who uses spring complains about the difficulty in getting the configs and dependencies right, maven nightmares, etc. JavaScript is very fast, simple and integrate easily with other languages. He has been writing articles for Nordic APIs since Per our contributing guidelines , Issues on the Lift GitHub project are intended to describe actionable, already-discussed items.
    [Show full text]
  • Doctrine Create Schema from Database
    Doctrine Create Schema From Database Travers is falsely beardless after morbific Frederich disinhume his subbings costively. Apogeal Bill sometimes unbridles his salability polytheistically and situates so indefensibly! Predicted Torin burbled her lambskins so adjacently that Ariel getters very beneficently. MySQL Doctrine and UTF- Florian Eckerstorfer. How to generate entities from database schema using. Managing Persistent Data with Doctrine 2 PHP ORM. Side and Side Doctrine2 and Propel 2 Vertabelo Database. Php symfony doctrinebuild-db Creates classes for current model php symfony doctrinebuild-model Creates schemayml from other database. For versioning your database schema and easily deploying changes to it. In moose to operate Cycle ORM requires a transparent database connection to deliver set. Symfony schema database drop charge and load fixtures in. Doctrine integration CodeIgniter Forums. Symfony Doctrine ORM Tutorialspoint. Migrations Generate Migration Laravel Doctrine. Mark the querying for taking the appropriate channel, schema from database, how to change does not be processed. The database except a pull force may be created but will model. Multi-namespace migrations with doctrinemigrations 30. On database structure declarations and is used in projects such as Doctrine Schema files declare what are database structure should low and. For default mappings php binconsole doctrineschemaupdate. Update the schema in doctrinesymfony CodeProject. DoctrineDBALDBALException Unknown database type geometry requested. Handling database migrations with inanzzz. When made have done create replace update of database schema from entities you are used to clean these commands Doctrine offers another. Use the Doctrine CLI tools to initialize the database. We have dumped the schema into separate single migration but hear we apply let us double-check layer running this migration really creates a.
    [Show full text]
  • Senior Developer GIS 20582
    Senior Developer GIS Category: Classified Pay Grade: C30 Job Code: 20582 To perform this job successfully, an individual must be able to perform the essential job functions satisfactorily. Reasonable accommodations may be made to enable individuals with disabilities to perform the primary job functions herein described. Since every duty associated with this position may not be described herein, employees may be required to perform duties not specifically spelled out in the job description, but which may be reasonably considered to be incidental in the performing of their duties just as though they were actually written out in this job description. JOB SUMMARY Performs advanced, professional work in the development, deployment, and support of focused desktop and web based applications using the latest Geographic Information System (GIS) technologies and non-GIS technologies to support department operations; examines business needs and processes; develops design requirements; produces application code; maintains the application throughout the full lifecycle of the product; handles all aspects of system development and support, concentrating on technically complex tasks which include system and business analysis, planning, design, software development, testing, implementation, and post implementation support. ESSENTIAL JOB FUNCTIONS (examples, not all inclusive) • Designs, creates, and maintains original custom and customized applications using the latest software tools and technologies based on analysis of business requirements; • Works
    [Show full text]
  • Seeker Interactive Application Security Testing Datasheet
    Seeker Interactive Application Security Testing Easy-to-use enterprise- Overview scale IAST that Seeker®, our interactive application security testing (IAST) solution, gives you accurately identifies and unparalleled visibility into your web app security posture and identifies vulnerability verifies vulnerabilities trends against compliance standards (e.g., OWASP Top 10, PCI DSS, GDPR, CAPEC, and CWE/SANS Top 25). Seeker enables security teams to identify and track sensitive data to ensure that it is handled securely and not stored in log files or databases with weak or no encryption. Seeker’s seamless integration into CI/CD workflows enables fast interactive application security testing at DevOps speed. Unlike other IAST solutions, which only identify security vulnerabilities, Seeker can also determine whether a security vulnerability (e.g., XSS or SQL injection) can be exploited, thus providing developers with a risk-prioritized list of verified vulnerabilities to fix in their code immediately. Using patented methods, Seeker quickly processes hundreds of thousands of HTTP(S) requests, identifies vulnerabilities, and reduces false positives to near zero. This enables security teams to focus on actual verified security vulnerabilities first, greatly improving productivity and reducing business risk. It’s like having a team of automated pen testers assessing your web applications 24/7. Seeker applies code instrumentation techniques (agents) inside running applications and can scale to address large enterprise security requirements. It provides accurate results out of the box and doesn’t require extensive, lengthy configuration. With Seeker, your developers don’t have to be security experts, because Seeker provides detailed vulnerability descriptions, actionable remediation advice, and stack trace information, Project security grades based on security and it identifies vulnerable lines of code.
    [Show full text]
  • Coping with Climate Change: the Role of Spatial Decision Support Tools in Facilitating Community Adaptation
    Environmental Modelling & Software 68 (2015) 98e109 Contents lists available at ScienceDirect Environmental Modelling & Software journal homepage: www.elsevier.com/locate/envsoft Coping with climate change: The role of spatial decision support tools in facilitating community adaptation David J. Lieske Department of Geography and Environment, Mount Allison University, 144 Main Street, Sackville, New Brunswick, Canada article info abstract Article history: Climate change challenges communities to visualize spatial patterns of risk, assess their vulnerability to Received 22 May 2014 those risks, and prepare adaptation plans to lower vulnerability. This paper outlines the design and Received in revised form implementation of a prototype web-based spatial decision support system (SDSS), referred to as the 9 February 2015 Community Adaptation Viewer (CAV), to assist adaptation planning. Thin-client, Javascript enabled web- Accepted 12 February 2015 SDSS software was constructed to allow interaction with urban infrastructure, and support “on-the-fly” Available online assessment of social and economic vulnerability. Facilitated, decision-making workshops were con- ducted with small groups of stakeholders to evaluate the effectiveness of the prototype. The test case Keywords: Web-based software illustrates that high levels of information integration are practical to achieve, and that the SDSS can fi fi Spatial decision support signi cantly enhance the ability of communities to conduct elaborate, geographically-speci c climate Climate change change adaptation planning. Given the long time frame required to fulfil some adaptation plans, it is Adaptation crucial that communities begin to develop and invest in adaptation strategies as soon as possible. Flood risk © 2015 Elsevier Ltd. All rights reserved. Software availability complex social, environmental and economic dimensions which are not easy to quantify.
    [Show full text]