38,39 €
Learn the fundamentals of ASP.NET MVC and build real-world web applications using ASP.NET Core MVC
This book is for developers who want to learn to build web applications using ASP.NET Core, developers who want to make a career building web applications using Microsoft technology, and developers who are working in Ruby on Rails or other web frameworks and want to learn ASP.NET Core MVC.
No knowledge of the ASP.NET platform or the .NET platform is required. Even though you do not need to have experience in C#, an understanding of the basic constructs (loops, conditionals, classes, and objects) of any modern programming language would be helpful.
ASP.NET Core MVC helps you build robust web applications using the Model-View-Controller design. This guide will help you in building applications which can be deployed on non-windows platforms such as Linux. In today's age, it is crucial that you possess the ability to separate the programming and business logic, and this is exactly what ASP.NET Core MVC application will help you achieve. This version comes with a number of improvements that enable fast, TDD-friendly development to create sophisticated applications. You would also learn the fundamentals of Entity framework and on how to use the same in ASP.NET Core web applications.
The book presents the fundamentals and philosophies of ASP.NET Core. Starting with an overview of the MVC pattern, we quickly dive into the aspects that you need to know to get started with ASP.NET. You will learn about the core architecture of model, view, and control.
Integrating your application with Bootstrap, validating user input, interacting with databases, and deploying your application are some of the things that you will be able to execute with this fast-paced guide. The end of the book will test your knowledge as you build a fully working sample application using the skills you've learned throughout the book.
This book takes a first-principles approach to help you understand and implement ASP.NET MVC solutions. It is focused primarily on giving you practical skills rather than the old conventional theoretical teaching.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 230
Veröffentlichungsjahr: 2016
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: November 2016
Production reference: 1101116
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78646-383-8
www.packtpub.com
Author
Mugilan T. S. Ragupathi
Copy Editor
Safis Editing
Reviewers
Anuraj Parameswaran
Mustafa Erhan Ersoy
Anand Ranjan Pandey
Project Coordinator
Suzanne Coutinho
Commissioning Editor
Edward Gordon
Proofreader
Safis Editing
Acquisition Editor
Indrajit Das
Indexer
Rekha Nair
Content Development Editor
Zeeyan Pinheiro
Graphics
Kirk D'Penha
Technical Editor
Pavan Ramchandani
Production Coordinator
Melwyn D'sa
Mugilan T. S. Ragupathi has been working on building web-based applications using Microsoft technology for more than a decade. He has been active in the ASP.NET community and has been running a successful blog, www.dotnetodyssey.com to help his fellow .NET developers.
His free beginners' course for ASP.NET MVC 5 (http://www.dotnetodyssey.com/asp-net-mvc-5-free-course/) was well received and is referred to as a concrete reference for beginners. He can be seen at csharp subreddit / Stack Overflow. He has written free micro eBooks, The 7 Most Popular Recipes of jQuery with ASP.NET Web Forms and Value & Reference types in C# (http://www.dotnetodyssey.com/free-ebooks/).
His book has received a good response and you can see the proof from one of his readers at https://twitter.com/jeffadamez. He is also an active contributor in Quora to the ASP.NET community (https://www.quora.com/profile/Mugil-Ragu). He likes to help readers with queries regarding ASP.NET.
Anuraj Parameswaran is a technical architect with Suyati Technologies (http://suyati.com/), Kochi. He has more than 12 years of extensive experience of working on different technologies, mostly in Microsoft space. He has been working on the .NET platform since its early days. He is a Microsoft Most Valuable Professional (MVP) in Visual Studio and Development Technologies. His focus areas are data analytics, architecture, and cloud computing. He is a K-MUG Community council member and an active volunteer in the Microsoft Technology Community. You can find his blog at http://dotnetthoughts.net.
Anuraj is also a reviewer of books and videos, namely, ASP.NET Web API Security Essentials, Learning ASP.NET Web API, and so on by Packt.
Mustafa Erhan Ersoy is a software team leader who is constantly evaluating new technologies and techniques in software development. He has been developing software professionally for 12 years and working mostly on ASP.NET web applications. He is very familiar with all aspects of transaction banking applications, BPM, and business workflows. He also blogs about web technologies, answers questions at stackoverflow.com, and participates in talks about ASP.NET and web technologies.
Anand Ranjan Pandey is currently working as a senior software developer for Dell. He is passionate about all aspects of software development, primarily and exclusively in the Microsoft .NET framework. He defines himself as an innovative technologist and visionary software developer with a passion for creating successful software products. He has comprehensive expertise in planning, managing, and achieving strategic business goals. Deep foundation in user-centered design, information architecture, and interactive new media.
He is an expert at building and leading cross-disciplinary technical teams and developing highly scalable and sustainable systems. He is successful at delivering technically challenging projects including enterprise e-commerce systems, secure exam portals, numerous software applications (web and shrink-wrap), content management systems, QA systems, networked publishing systems, and large-scale interactive multimedia learning exhibits.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.
The book aims to help you learn the fundamentals of ASP.NET Core MVC and apply that knowledge to building applications using ASP.NET Core. This book also aims to serve as a solid guide for beginners who want to learn ASP.NET MVC. In detail, the following topics are going to be covered in the book:
Chapter 1, Introduction to ASP.NET Core, covers the fundamentals of ASP.NET MVC and how it fits in the ASP.NET ecosystem. This chapter explains the basics of web development, including client-side components and server-side components and what a programmer can do and can’t do in either layer
Chapter 2, Setting up the Environment, shows the reader how to set up the development environment, including the installation of Visual Studio and ASP.NET Core. Hardware and software requirements for setting up the development environment is also discussed and the anatomy of ASP.NET MVC applications is presented.
Chapter 3, Controllers, explains about what constitutes a Controller and action method along with its roles and responsibilities. In this chapter, a simple Controller along with an action method will be created. It will explain to the readers what an action method and a Controller does from the perspective of an overall ASP.NET MVC application.
Chapter 4, Views, presents what the Razor View engine does and explains the various basic programming constructs (conditionals, loops, and so on) with the examples using Razor view engine.
Chapter 5, Models, presents the role of Models in ASP.NET Core application. The concept of ViewModel is discussed along with how it provides flexibility and data compartmentalization to your applications.
Chapter 6, Validation, explains client-side and server-side validation with JavaScript and by using the jQuery libraries.
Chapter 7, Routing, explains about the routing module, which selects the appropriate controller from the received request with an example. Various options and features of routing are presented. This chapter will also guide you through building a custom route for ASP.NET MVC application based on business logic or for SEO purposes.
Chapter 8, Beautifying ASP.NET Application with Bootstrap, teaches how to use Bootstrap, a responsive frontend framework, to prettify your applications. You will be guided through the creation of HTML form controls.
Chapter 9, Deployment of ASP.NET Core Application, explains how the project.json library handles all of the dependencies of ASP.NET Core applications, along with the versions. It also explains how the K runtime (the latest option in ASP.NET Core application) so that an ASP.NET MVC application could be deployed in a non-Windows environment as well.
Chapter 10, Building Web Services Using Web API, explains HTTP-based services and how to implement them using the Web API. It will also introduce you to the Fiddler, and to compose an HTTP request using it.
Chapter 11, Improving Performance of an ASP.NET Core Application, explains the approaches to analyzing of performance and measures for improvement in various layers of your application.
Chapter 12, ASP.NET Core Identity, explains the security aspects of your application and implementing security identity of an application using Entity Framework.
To start programming the ASP.NET MVC applications, you will need Visual Studio Community 2015 IDE. This is a fully featured IDE available for building desktops and web applications. You will also need various packages and frameworks, such as NuGet, Bootstrap, and project.json, the installation and configuration of which will be explained in the book.
This book is for developers who want to learn how to build web applications using ASP.NET Core, developers who want to make a career building web applications using Microsoft technology, and developers who are working in Ruby on Rails or other web frameworks and want to learn how to use ASP.NET Core MVC.
No knowledge of the ASP.NET platform or the .NET platform is required. Even though you do not need to have experience with C#, an understanding of the basic constructs (loops, conditionals, classes, and objects) of any modern programming language would be helpful.
Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
You can download the code files by following these steps:
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/learning-asp-dot-net-core-programming . We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/LearningAspDotNetCoreProgramming_ColorImages.pdf.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at [email protected] with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.
ASP.NET Core, the latest version of ASP.NET MVC from Microsoft, is the server-side web application development framework which helps you to build web applications effectively. This runs on top of the ASP.NET 5 platform, which enables your application to be run on a wide variety of platforms, including Linux and Mac OS X. This opens up heaps of opportunities and it is exciting to be a .NET developer in these times.
In this chapter, you'll learn about the following topics:
Before discussing the ASP.NET Core and its features, let us understand the fundamentals of web applications development. I strongly believe the principle that if you want to be an expert at something, you need to be very good at the fundamentals. It will be helpful in debugging the issues and fixing them.
Having said that we are going to discuss the following key fundamentals:
Just three key concepts. No big deal!
All web applications, irrespective of whether they are built using ASP.NET MVC, Ruby on Rails, or any other new shiny technology, work on the HTTP protocol. Some applications use HTTPS (a secure version of HTTP), where data is encrypted before passing through the wire. But HTTPS still uses HTTP.
HTTP stands for Hyper Text Transfer Protocol and is an application protocol which is designed for distributed hypermedia systems. "Hyper Text" in Hyper Text Transfer Protocol refers to the structured text that uses hyperlinks for traversing between the documents. Standards for HTTP were developed by the Internet Engineering Task Force (IETF) and the World Wide Web Consortium(W3C). The current version of HTTP is HTTP/2 and was standardized in 2015. It is supported by the majority of web browsers, such as Internet Explorer, Chrome, and Firefox.
The HTTP protocol (a protocol is nothing but a set of rules which govern the communication) is a stateless protocol that follows the request-response pattern.
Before talking about the request-response pattern, let us discuss a couple of terms: Client and server. A server is a computing resource that receives the requests from the clients and serves them. A server, typically, is a high-powered machine with huge memory to process many requests. A client is a computing resource that sends a request and receives the response. A client, typically, could be a web server or any application that sends the requests.
Coming back to the request-response pattern, when you request a resource from a server, the server responds to you with the requested resource. A resource could be anything—a web page, text file, an image , or another data format.
You fire a request. The server responds with the resource. This is called a request-response pattern.
When you request for the same resource again, the server responds to you with the requested resource again without having any knowledge of the fact that the same was requested and served earlier. The HTTP protocol inherently does not have any knowledge of the state knowledge of any of the previous requests received and served. There are several mechanisms available that maintain the state, but the HTTP protocol by itself does not maintain the state. We will explain the mechanisms to maintain the state later.
Let me explain to you about the statelessness and the request-response pattern to you with a simple practical example:
As mentioned earlier, there are several mechanisms to maintain the state. Let us assume, for the time being, that no such mechanism is implemented here. I know that I am being too simplistic here, but this explains the point.
It is necessary to understand the client-side and server-side of web applications and what can be done either side. With respect to web applications, your client is the browser and your server could be the web server/application server.
The browser side is whatever that happens in your browser. It is the place where your JavaScript code runs and your HTML elements reside.
The server-side is whatever happens at the server at the other end of your computer. The request that you fire from your browser has to travel through the wire (probably across the network) to execute some server-side code and returns the appropriate response. Your browser is oblivious to the server-side technology or the language your server-side code is written in. The server-side is also the place where your C# code resides.
Let us discuss some of the facts to make things clear:
Even though all the requests of the HTTP protocol follow the request-response pattern, the way the requests are sent can vary from one to the next. The HTTP method defines how the request is being sent to the server.
The available methods in HTTP are GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, and PATCH. In most of the web applications, the GET and POST methods are widely used. In this section, we will discuss these methods. Later, we will discuss other HTTP methods on a need-to-know basis.
GET is a method of the HTTP protocol which is used to get a resource from the server. Requests which use the GET method should only retrieve the data and should not have any side effect. This means that if you fire the same GET request, again and again, you should get the same data, and there should not be any change in the state of the server, as a result of this GET request.
In the GET method, the parameters are sent as part of the request URL and therefore will be visible to the end user. The advantage of this approach is that the user can bookmark the URL and visit the page again whenever they want. An example is www.yourwebsite.com?tech=mvc6&db=sql.
We are passing a couple of parameters in the preceding GET request. tech is the first parameter with the value mvc6 and db is the second parameter with the value sql
