ASP.NET Core MVC 2.0 Cookbook

Book description

Learn to implement ASP.NET Core features to build effective software that can be scaled and maintained easily

About This Book

  • Practical solutions to recurring issues in the web development world
  • Recipes on the latest features of ASP.Net Core 2.0
  • Coverage of Bootstrap, Angular, and JavaScript lets you supercharge your frontend

Who This Book Is For

This book is written for the ASP.NET developer who wants to deliver professional-standard software, quickly and efficiently. It's filled with hands-on recipes, practical advice, and guidance to help developers with every aspect of the ASP.NET development cycle. Whether you've just started out or are a seasoned pro, the Asp.Net Core 2.0 Cookbook is written for you.

What You Will Learn

  • Build ASP.Net Core 2.0 applications using HTTP services with WebApi
  • Learn to unit-test, load test, and perform test applications using client-side and server-side frameworks
  • Debug, monitor and troubleshoot ASP.Net Core 2.0 applications using popular tools
  • Reuse components with NuGet and create modular components with middleware
  • Create applications using client-side technologies such as HTML5, JavaScript, jQuery, and Angular
  • Build responsive and dynamic UIs for your MVC apps using Bootstrap
  • Leverage tools like Karma, Jasmine, QUnit, xUnit, Selenium, Microsoft Fakes, and Visual Studio 2017 Enterprise

In Detail

The ASP.NET Core 2.0 Framework has been designed to meet all the needs of today's web developers. It provides better control, support for test-driven development, and cleaner code. Moreover, it's lightweight and allows you to run apps on Windows, OSX and Linux, making it the most popular web framework with modern day developers.

This book takes a unique approach to web development, using real-world examples to guide you through problems with ASP.NET Core 2.0 web applications. It covers Visual Studio 2017- and ASP.NET Core 2.0-specifc changes and provides general MVC development recipes. It explores setting up .NET Core, Visual Studio 2017, Node.js modules, and NuGet. Next, it shows you how to work with Inversion of Control data pattern and caching. We explore everyday ASP.NET Core MVC 2.0 patterns and go beyond it into troubleshooting. Finally, we lead you through migrating, hosting, and deploying your code.

By the end of the book, you'll not only have explored every aspect of ASP.NET Core MVC 2.0, you'll also have a reference you can keep coming back to whenever you need to get the job done.

Style and approach

Asp.Net Core 2.0 has been redesigned to meet the needs of today's web developers. Open-source, cross-platform, and fully integrated with the most powerful front-end frameworks, it still has all the benefits of ease and speed of development that have made it one of the most popular web frameworks in production today. Asp.Net Core 2.0 Development Cookbook takes a unique approach to web development. Based around the tasks that you will be using every day when making websites, it will guide you through all the common problems you'll face when developing web applications.

Publisher resources

View/Submit Errata

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. ASP.NET Core MVC 2.0 Cookbook
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the authors
    2. About the reviewers
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Get in touch
      1. Reviews
  6. Cross-Platform with .NET Core
    1. What is ASP.NET Core 2.0?
    2. What's new in ASP.NET and CLR?
    3. Installing or updating .NET Core
      1. How to do it...
      2. How it works...
    4. Managing NuGet packages in ASP.NET Core applications
      1. How to do it...
    5. Creating an ASP.NET Core MVC application on Linux
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Creating an ASP.NET Core MVC application on Linux with Docker
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Creating an ASP.NET Core MVC application on macOS
      1. Getting ready
      2. How to do it...
    8. Creating and running an ASP.NET Core MVC application on Azure
      1. Getting started
      2. How to do it...
      3. How it works...
  7. Visual Studio 2017, C# 6, IDEs, and Roslyn
    1. Introduction
    2. Working with Visual Studio 2017
      1. How to do it...
    3. Working with Visual Studio Code
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Installing and using OmniSharp on macOS
      1. How to do it...
      2. How it works...
      3. See also
    5. Installing and using OmniSharp on Linux
      1. Getting ready
      2. How to do it...
    6. Working with Roslyn
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. APIs
    7. Using C# 6 new features
      1. How to do it...
      2. See also...
  8. Working with npm, Frontend Package Managers, and Task Runners
    1. Introduction
    2. Using and creating npm modules
      1. Getting ready
      2. How to do it...
        1. Creating a node package
        2. Publishing the package
      3. How it works...
      4. There's more...
    3. Managing frontend dependencies with Bower
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Compiling LESS files to CSS files with Grunt
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Bundling and minifying JavaScript files with Gulp
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Using Yeoman code-generated templates
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Using JSPM
      1. Getting ready
      2. How to do it...
      3. How it works...
  9. Reusing Code with NuGet
    1. Introduction
    2. Managing NuGet packages
      1. Getting ready
      2. How to do it...
      3. See also
    3. Creating a NuGet package with the NuGet package class library
      1. Getting ready
      2. How to do it...
        1. The old way
        2. The new way
    4. Creating a local NuGet repository and consuming packages from it
      1. How to do it...
    5. Creating a NuGet package with NuGet Package Explorer
      1. How to do it...
    6. Sharing NuGet packages with the community
      1. How to do it...
    7. Creating an Azure NuGet repository
      1. How to do it...
  10. SOLID Principles, Inversion of Control, and Dependency Injection
    1. Introduction
      1. SOLID principles
      2. Inversion of control
      3. Dependency injection (DI)
      4. DI containers
      5. Configuring a DI container
      6. IOC versus service locator
      7. Life cycles
    2. Implementing DI with Native IOC in ASP.NET Core
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Using the life cycles available in ASP.NET Core
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Implementing DI with Autofac
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Implementing DI with StructureMap
      1. How to do it...
      2. How it works...
    6. Implementing DI with DryIoc
      1. Getting ready
      2. How to do it...
      3. How it works...
  11. Data Access - EF7 with Repository, SQL Server, and Stored Procedures
    1. Introduction
      1. DbContext
      2. Entity Framework (EF) approach
    2. Configuring the IOC life cycle for the repository pattern
      1. Getting ready
      2. How to do it...
    3. Using EF with an existing database
      1. Getting ready
      2. How to do it...
    4. Using an InMemory provider
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Managing a long request batch
      1. Getting ready
      2. How to do it...
      3. There's more...
    6. Using a stored procedure with EF
      1. Getting ready
      2. How to do it...
    7. Writing an EF provider
      1. Getting ready
      2. How to do it...
      3. See also
  12. Accessing data with Micro ORMs, NoSQL, and Azure
    1. Introduction
      1. Micro ORMs
      2. NoSQL
    2. Accessing data with Dapper
      1. Getting ready
      2. How to do it...
      3. There's more...
    3. Accessing data with OrmLite
      1. Getting ready
      2. How to do it...
    4. Accessing data with MongoDb
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Accessing data with Windows Azure storage tables
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Accessing data with Azure storage Blobs
      1. Getting ready
      2. How to do it...
    7. Accessing data with SQL Azure
      1. Getting ready
      2. How to do it...
  13. Cache and Session - Distributed, Server, and Client
    1. Introduction
    2. Using .NET Cache with MemoryCache
      1. Getting ready
      2. How to do it...
    3. Caching HTML with Cache TagHelpers
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Using ResponseCache attribute
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using Session
      1. Getting ready
      2. How to do it......
      3. How it works...
    6. Using Redis as Cache on-Premises
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Using Redis as a cache on Azure
      1. Getting ready
      2. How to do it...
    8. Caching with HTML5 cache manifest
      1. Getting ready
      2. How to do it...
      3. How it works......
    9. Caching with HTML5 localStorage and sessionStorage
      1. Getting ready
      2. How to do it...
      3. How it works......
      4. See also
  14. Routing
    1. Before ASP.NET Core
    2. Since ASP.NET Core
    3. MVC and Web API routing
    4. The route order
    5. Routing with ASP.NET Core
    6. Creating a route using convention routing
      1. How to do it...
      2. How it works...
    7. Creating a route using attribute routing
      1. Getting ready
      2. How to do it...
    8. Creating a custom route using IRouter
      1. Getting ready
      2. How to do it...
    9. Creating a route constraint
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Creating a domain route
      1. Getting ready
      2. How to do it...
    11. Creating SEO-friendly routes
      1. Getting ready
      2. How to do it...
  15. ASP.NET Core MVC
    1. Injecting dependencies and configuring IoC for a controller
      1. Getting ready
      2. How to do it...
    2. Using ActionResults
      1. Getting ready
      2. How to do it...
    3. Creating and working with areas
      1. Getting ready
      2. How to do it...
    4. Creating and using POCO controllers
      1. Getting ready
      2. How to do it...
    5. Creating and using controllers with MediatR
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Managing exceptions
      1. Getting ready
      2. How to do it...
  16. Web API
    1. Using ActionResult
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Configuring content negotiation
      1. Getting ready
      2. How to do it...
    3. Configuring cross-domain origin requests
      1. Getting ready
      2. How to do it...
    4. Using Swagger
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Testing Web API
      1. Getting ready
      2. How to do it...
      3. There's more...
    6. Managing exceptions
      1. Getting ready
      2. How to do it...
      3. There's more...
  17. Filters
    1. Introduction
    2. Managing authentication and authorization with policies, requirements, and filters
      1. Getting ready
      2. How to do it...
        1. Authentication
      3. There's more...
    3. Managing dependency injection with filters
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Creating and using an action filter
      1. Getting ready
      2. How to do it...
    5. Creating and using a result filter
      1. Getting ready
      2. How to do it...
    6. Creating and using a resource filter
      1. Getting ready
      2. How to do it...
    7. Creating and using an exception filter
      1. Getting ready
      2. How to do it...
    8. Using a filter globally versus using a middleware
      1. Getting ready
      2. How to do it...
      3. There's more...
  18. Views, Models, and ViewModels
    1. Creating and using a ViewModel with AutoMapper
      1. Getting ready
      2. How to do it...
    2. Understanding and using ModelBinding
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Creating our own model binder
      1. Getting ready
      2. How to do it...
    4. Understanding and using a value provider
      1. Getting ready
      2. How to do it...
    5. Configuring and using validation
      1. Getting ready
      2. How to do it...
  19. Razor and Views
    1. Managing namespaces in views with ViewImports
      1. Getting ready
      2. How to do it...
    2. Creating a strongly typed Partial view
      1. Getting ready
      2. How to do it...
    3. Configuring view and area locations
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Using dependency injection in views
      1. Getting ready
      2. How to do it...
    5. Creating HTMLHelpers
      1. Getting ready
      2. How to do it...
      3. How it works...
  20. TagHelpers and ViewComponents
    1. Using Environment, Script, and Link TagHelpers
      1. Getting ready
      2. How to do it...
    2. Using Form TagHelpers
      1. Getting ready
      2. How to do it...
    3. Creating TagHelpers programmatically
      1. Getting ready
      2. How to do it...
      3. There's more...
    4. Creating a reusable view component
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating a view component/controller class
      1. Getting ready
      2. How to do it...
      3. How it works...
  21. OWIN and Middleware
    1. Understanding OWIN, Katana, and the new ASP.NET Core HTTP pipeline
      1. OWIN - an abstraction for decoupling
      2. Katana - the Microsoft OWIN implementation
      3. A new OWIN implementation with ASP.NET Core
      4. The ASP.NET Core pipeline
      5. Middleware
      6. HTTP modules and HTTP handlers
    2. Using inline middleware code as anonymous methods - Use, Run, Map, and MapWhen
      1. Getting ready
      2. How to do it...
    3. Creating a reusable middleware component
      1. Getting ready
      2. How to do it...
    4. Migrating an HTTP handler to middleware
      1. Getting ready
      2. How to do it...
    5. Migrating HTTP modules to middleware
      1. Getting ready
      2. How to do it...
  22. Security
    1. Introduction
      1. Authentication in the real world
        1. Authentication sample
    2. Authentication in ASP.NET, using cookie authentication
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Authentication using authorization servers
      1. Getting ready
      2. How to do it...
        1. Using Facebook as an authorization server
        2. Using Google as an authorization server
      3. How it works...
    4. Managing identity
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Securing data with Hashing
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Securing data with Encryption
      1. Getting ready
      2. How to do it...
      3. How it works...
  23. Frontend Development
    1. Using Bootstrap
      1. Getting ready
        1. Advantages of using CDN
      2. How to do it...
      3. How it works...
    2. Writing clean JavaScript
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. RequireJS
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Typescript
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Writing and executing unit tests in JavaScript
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Debugging JavaScript code in browsers
      1. Getting ready
      2. How to do it...
      3. How it works...
  24. Deployment and Hosting
    1. Deployment options
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Hosting an ASP.NET Core web app on IIS
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Hosting an ASP.NET Core web application on Kestrel
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Hosting an ASP.NET Core web app on Azure
      1. Getting ready
      2. How to do it...
        1. Deploying an ASP.NET Core web app to Azure with Visual Studio Code
        2. Deploying an ASP.NET Core web app to Azure with Visual Studio Community Edition
      3. How it works...
    5. Hosting an ASP.NET Core web app in Docker containers
      1. Getting ready
      2. How to do it...
      3. How it works...
  25. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: ASP.NET Core MVC 2.0 Cookbook
  • Author(s): Engin Polat, Stephane Belkheraz
  • Release date: February 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781785886751