29,99 €
Develop and deploy modern cross-platform web applications with ASP.NET Core
This book is for software developers who have experience in .NET, preferably with C# or some other Object-Oriented Programming Language, which is required in order to build ASP.NET Core web applications. A basic understanding of web application development is also essential.
ASP.NET Core is the latest collection of Microsoft's web application development technologies. When you're trying to reach a broad spectrum of users with a robust web application, ASP.NET Core is there to help you build that application. With the ability to cater to users on desktop, tablet, or smartphone platforms, you can put together a solution that works well anywhere.
This book is what you need to get started developing ASP.NET Core applications was quickly as possible; starting by introducing the software and how it can be used in today's modern world of web applications and smartphone apps. Walking you through the benefits of a Web API to support both applications and mobile apps to give you a solid understanding of the tech to build upon as you see what ASP.NET Core can do for you.
The book wraps up with practical guidelines for the use of database technologies, unit tests, security best practices, and cloud deployments for the real world.
This is a comprehensive guide for .NET developers to build the next generation of web apps. This book can be read from start to finish, but you can also come back to any chapter for a quick refresher, as each chapter is modularized for specific concepts.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 198
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: September 2016
Production reference: 1160916
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78588-915-8
www.packtpub.com
Author
Shahed Chowdhuri
Copy Editor
Safis Editing
Reviewer
Steve Albers
Project Coordinator
Ulhas Kambali
Commissioning Editor
Dipika Gaonkar
Proofreader
Safis Editing
Acquisition Editor
Sonali Vernekar
Indexer
Rekha Nair
Content Development Editor
Prashanth G
Graphics
Kirk D'Penha
Technical Editor
Sushant S Nadkar
Production Coordinator
Melwyn Dsa
Shahed Chowdhuri has over 18 years of experience in the field of professional software development, and is currently a Senior Technical Evangelist at Microsoft Corporation. He began his career with what is now known as Classic ASP, and worked with ASP.NET as it continued to evolve over the years. He is a public speaker in the DC metro area and along the East Coast of the United States. He serves as a mentor for startups and indie developers at 1776 DC, and also manages multiple developer groups on Facebook and Meetup. You can find him blogging at WakeUpAndCode.com or on Twitter via @shahedC.
Steve Albers is a software developer and speaker living in Northern Virginia.
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://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Web applications have flourished in enterprise application development, even as mobile applications continue to rise in popularity. Moreover, the use of web APIs provides greater flexibility when it comes to building a backend that can serve both web apps and mobile apps. With ASP.NET Core 1.0, you get the benefits of a mature programming language such as C# with the performance of an all-new .NET Core that allows your web apps and web APIs to run on Windows, Mac, and Linux.
ASP.NET Core lets you choose your operating system during development, whether you're writing your code on a Surface Book, MacBook Air, or on a popular distribution of Linux. While this book primarily covers development on Visual Studio 2015 on a Windows system, you will find links to online guides if you wish to set up your environment on a different operating system.
ASP.NET Core 1.0 Essentials will introduce you to Microsoft's latest revision of ASP.NET, with everything you need to get started today. If you have already worked with ASP.NET MVC before, you will get a refresher of a few things you already know, followed by what's new. If you've only worked with ASP.NET Web Forms or other competing web frameworks, you will find the initial chapters very useful in laying the groundwork for what you need to know.
Chapter 1, Getting Started with ASP.NET Core, teaches you about ASP.NET Core 1.0, including MVC and web API. This chapter will explain the differences between the full .NET Framework 4.6 and .NET Core, while introducing Visual Studio 2015 and the all-new cross-platform Visual Studio Code.
Chapter 2, Building Your First ASP.NET Core Application, shows you how to create a new ASP.NET Core web application. This chapter will dissect the parts of a modern ASP.NET web application, while explaining what's new and what's changed.
Chapter 3, Understanding MVC, teaches you all about ASP.NET Core MVC by going deeper into controllers, views, and models. This chapter will explain how to create all the parts of a modern MVC application and then bring it all together.
Chapter 4, Using Web API to Extend Your Application, is about using the web API to extend your web application to support web and mobile applications. This chapter will explain how to create routes and configure a web API application and then consume it from a client application.
Chapter 5, Interacting with Web API using JavaScript, teaches you how to interact with the ASP.NET web API using straight JavaScript as well as popular frameworks such as AngularJS and KnockoutJS. This chapter will also cover developer tools, which automate important tasks and help during the development process.
Chapter 6, Using Entity Framework to Interact with Your Database in Code, teaches you how to use Entity Framework in the data layer of your web application. This chapter will introduce object-relational mapping (ORM) tools and the use of EF Code First Migrations .
Chapter 7, Dependency Injection and Unit Testing for Robust Web Apps, shows you how to implement dependency injection by using Inversion of Control . This chapter will cover DI, IoC containers, and Microsoft's new built-in support for dependency injection. The chapter will also cover the basics of unit testing.
Chapter 8, Authentication, Authorization, and Security, is about enabling authentication in ASP.NET web applications while implementing authorization for specific application features. The chapter will also cover guidelines for protecting user data and strategies to combat common security vulnerabilities in web applications.
Chapter 9, Deploying Your Application, covers how to deploy your applications to IIS on a web server or on Microsoft's Azure cloud platform. The chapter will also cover the use of continuous integration to run unit tests and deploy successfully compiled applications.
To learn ASP.NET Core and run the code examples for this book, the following software is recommended:
For more information on developing for and running ASP.NET Core on systems other than Windows, please consult the Running ASP.NET Core on Windows, Mac OS X, Linux section in Chapter 1, Getting Started with ASP.NET Core. There, you will find a high-level overview of instructions for Mac and Linux, with links to online guides that are frequently updated.
This book is for software developers who have experience in .NET, preferably with C# or some other object-oriented programming language, which is required in order to build ASP.NET Core web applications. A basic understanding of web application development is also essential.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Uses the HTTP GET method with optional querystring parameters"
A block of code is set as follows:
app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); });Any command-line input or output is written as follows:
dotnet restoredotnet builddotnet ef migrations add Initialdotnet ef database updateNew terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Enter some values and click the Create button."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
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/ASPdotNET-Core-Essentials. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
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.
Active Server Pages was first made available on Microsoft's IIS web server in the mid-1990s. Fast-forward about 20 years, and ASP.NET Core (that is, ASP.NET 5 while in development) is now open source and runs on Windows, Linux, and OS X. Moreover, Visual Studio is now available as a cross-platform lightweight code editor in addition to the full-featured IDE on Windows.
As a .NET developer, you can take advantage of all the recent improvements, while building on the experience that you already have. The .NET Framework has evolved beyond the full framework and is now available as a cross-platform runtime called .NET Core.
In this chapter, we will discuss the following principles and concepts to get you started with ASP.NET Core:
When developers hear the term ASP.NET, some associate it with ASP.NET Web Forms, while others think of ASP.NET MVC or even Web API. Many developers have started their journey with Web Forms, and have migrated to Model-View-Controller (MVC) in recent years.
The adoption of ASP.NET MVC has been on the rise for years, due to its cleaner code and testability. While you can still develop Web Forms on .NET 4.x, you will be using MVC on .NET Core 1.0. Fortunately, ASP.NET Core runs on both .NET 4.5.1+ and .NET Core, so you can choose which runtime you would like to target.
Going forward, Microsoft has unified MVC, Web API, and Web Pages in ASP.NET Core. What does this mean for you, the developer? It means that you will enjoy more consistency when building your application with MVC, Web API, and Web Pages. In the past, MVC and Web API were implemented separately, leading to duplication and inconsistencies, but with ASP.NET Core, they have been merged into a single programming model.
If you're new to any of the preceding terms, here's a high-level overview:
The following figure illustrates a typical ASP.NET web application that uses both MVC and Web API. Note that Web API can be used to serve clients other than web browsers, such as mobile apps. It's important to mention that browsers here can include mobile web browsers as well:
You may have noticed that I mentioned MVC 6 while talking about ASP.NET Core. ASP.NET MVC 6 has been renamed ASP .NET Core 1.0 MVC. To keep track of all the new version numbers, the following is a handy list of what you need to know:
Now that you're familiar with the moving parts of ASP.NET Core and its various version numbers, how will you decide which parts to use? The good news is that you won't have to figure it all out before you get started on your project.
Think about the requirements of your web software project and the needs of your customers. Choose the technologies that make sense for you and your team, and get started on a Minimum Viable Product (MVP).
If you need to support web browsers, go with ASP.NET MVC and build responsive web applications that look good on any screen size. If you need to extend your application with Web API, expose only what needs to be exposed.
If you need real-time functionality, SignalR is a great place to start. At the time of writing, Microsoft has announced that SignalR 3 will not be included with the 1.0 release of ASP.NET Core. As a result of this, SignalR 3 will not be covered in this book. For more information, stay tuned to the SignalR website: http://www.asp.net/signalr .
Since the inception of .NET Framework, there has always been one release at a time. Whenever a newer version was released, you could upgrade to the latest version or install multiple versions side by side. But there was always one single latest version.
Going forward, there are now two distinct versions: the full .NET Framework and the all-new .NET Core. While ASP.NET Core web applications can run on either one of them, you will decide which is more suitable for your needs. You can change the runtime during development or during release. Best of all, you can deploy the runtime alongside your released product, which allows multiple versions of .NET to be deployed to the same server.
The following screenshot illustrates how ASP.NET Core runs on both .NET Framework 4.6 and .NET Core 1.0:
Even with the release of .NET Core, there is still a place for the full .NET Framework. It will continue to be the framework of choice for rich Windows desktop applications, created with Windows Presentation Foundation (WPF) or Windows Forms. It will be one of two choices for ASP.NET Core developers.
For ASP.NET 4 developers, .NET Framework 4.6 will be an in-place replacement for .NET 4.x runtimes. This includes .NET 4, 4.5, 4.5.1, and 4.5.2. One good reason to upgrade to .NET 4.6 is the added benefit of new improvements such as better compilation and added language features.
The new .NET Core is a lightweight cross-platform subset of the full .NET Framework that makes its home on Windows, Linux, and OS X. It is expected to leap past the .NET Framework in new features that may make their way back to the .NET Framework.
It is worth noting that .NET Core is not an option for Windows desktop developers or ASP.NET 4 developers. In addition to supporting ASP.NET Core web applications with the CoreCLR runtime, .NET Core also includes the .NET native runtime, which is specifically used for Universal Windows Applications on Windows 10.
To recap, let's focus on the following benefits of running an ASP.NET Core web application on .NET Core, in addition to its cross-platform support:
