Merge pull request #4694 from aspnet/master

Update live with current master
pull/4758/head^2
Rick Anderson 2017-10-31 11:26:19 -10:00 committed by GitHub
commit f5e5da8fa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 40 deletions

View File

@ -1,22 +1,24 @@
---
title: Configuration in ASP.NET Core
author: rick-anderson
description: Learn how to use the Configuration API to configure an ASP.NET Core app from multiple sources.
keywords: ASP.NET Core,configuration,JSON,config
description: Use the Configuration API to configure an ASP.NET Core app by multiple methods.
keywords: ASP.NET Core,configuration,JSON,config,ini,XML,provider
ms.author: riande
manager: wpickett
ms.date: 6/24/2017
ms.date: 11/01/2017
ms.topic: article
ms.assetid: b3a5984d-e172-42eb-8a48-547e4acb6806
ms.technology: aspnet
ms.prod: asp.net-core
uid: fundamentals/configuration
---
# Configuration in ASP.NET Core
# Configure an ASP.NET Core App
[Rick Anderson](https://twitter.com/RickAndMSFT), [Mark Michaelis](http://intellitect.com/author/mark-michaelis/), [Steve Smith](https://ardalis.com/), [Daniel Roth](https://github.com/danroth27), and [Luke Latham](https://github.com/guardrex)
The Configuration API provides a way of configuring an app based on a list of name-value pairs. Configuration is read at runtime from multiple sources. The name-value pairs can be grouped into a multi-level hierarchy. There are configuration providers for:
The Configuration API provides a way to configure an ASP.NET Core web app based on a list of name-value pairs. Configuration is read at runtime from multiple sources. You can group these name-value pairs into a multi-level hierarchy.
There are configuration providers for:
* File formats (INI, JSON, and XML)
* Command-line arguments
@ -78,7 +80,7 @@ Configuration considerations:
<a name="options-config-objects"></a>
## Using Options and configuration objects
## Use Options and configuration objects
The options pattern uses custom options classes to represent a group of related settings. We recommended that you create decoupled classes for each feature within your app. Decoupled classes follow:
@ -157,13 +159,13 @@ The following sample demonstrates how a new `IOptionsSnapshot` is created after
The following image shows the server output:
![browser image showing "Last Updated: 11/22/2016 4:43 PM"](configuration/_static/first.png)
![browser shows image with text that says "Last Updated: 11/22/2016 4:43 PM"](configuration/_static/first.png)
Refreshing the browser doesn't change the message value or time displayed (when *config.json* has not changed).
Change and save the *config.json* and then refresh the browser:
![browser image showing "Last Updated to,e: 11/22/2016 4:53 PM"](configuration/_static/change.png)
![browser shows image with text that says "Last Updated to,e: 11/22/2016 4:53 PM"](configuration/_static/change.png)
## In-memory provider and binding to a POCO class
@ -193,7 +195,7 @@ The following sample demonstrates the [GetValue<T>](https://docs.microsoft.com/a
The ConfigurationBinder's `GetValue<T>` method allows you to specify a default value (80 in the sample). `GetValue<T>` is for simple scenarios and does not bind to entire sections. `GetValue<T>` gets scalar values from `GetSection(key).Value` converted to a specific type.
## Binding to an object graph
## Bind to an object graph
You can recursively bind to each object in a class. Consider the following `AppOptions` class:
@ -244,7 +246,7 @@ public void CanBindObjectTree()
<a name="custom-config-providers"></a>
## Basic sample of Entity Framework custom provider
## Create an Entity Framework custom provider
In this section, a basic configuration provider that reads name-value pairs from a database using EF is created.
@ -294,7 +296,7 @@ The [CommandLine configuration provider](/aspnet/core/api/microsoft.extensions.c
[View or download the CommandLine configuration sample](https://github.com/aspnet/docs/tree/master/aspnetcore/fundamentals/configuration/sample/CommandLine)
### Setting up the provider
### Setup and use the CommandLine configuration provider
# [Basic Configuration](#tab/basicconfiguration)

View File

@ -35,13 +35,13 @@ Tag Helpers enable server-side code to participate in creating and rendering HTM
Most of the built-in Tag Helpers target existing HTML elements and provide server-side attributes for the element. For example, the `<input>` element used in many of the views in the *Views/Account* folder contains the `asp-for` attribute, which extracts the name of the specified model property into the rendered HTML. The following Razor markup:
```html
```cshtml
<label asp-for="Email"></label>
```
Generates the following HTML:
```html
```cshtml
<label for="Email">Email</label>
```
@ -57,13 +57,13 @@ Tag Helpers scope is controlled by a combination of `@addTagHelper`, `@removeTag
If you create a new ASP.NET Core web app named *AuthoringTagHelpers* (with no authentication), the following *Views/_ViewImports.cshtml* file will be added to your project:
[!code-html[Main](../../../mvc/views/tag-helpers/authoring/sample/AuthoringTagHelpers/src/AuthoringTagHelpers/Views/_ViewImportsCopy.cshtml?highlight=2&range=2-3)]
[!code-cshtml[Main](../../../mvc/views/tag-helpers/authoring/sample/AuthoringTagHelpers/src/AuthoringTagHelpers/Views/_ViewImportsCopy.cshtml?highlight=2&range=2-3)]
The `@addTagHelper` directive makes Tag Helpers available to the view. In this case, the view file is *Views/_ViewImports.cshtml*, which by default is inherited by all view files in the *Views* folder and sub-directories; making Tag Helpers available. The code above uses the wildcard syntax ("\*") to specify that all Tag Helpers in the specified assembly (*Microsoft.AspNetCore.Mvc.TagHelpers*) will be available to every view file in the *Views* directory or sub-directory. The first parameter after `@addTagHelper` specifies the Tag Helpers to load (we are using "\*" for all Tag Helpers), and the second parameter "Microsoft.AspNetCore.Mvc.TagHelpers" specifies the assembly containing the Tag Helpers. *Microsoft.AspNetCore.Mvc.TagHelpers* is the assembly for the built-in ASP.NET Core Tag Helpers.
To expose all of the Tag Helpers in this project (which creates an assembly named *AuthoringTagHelpers*), you would use the following:
[!code-html[Main](../../../mvc/views/tag-helpers/authoring/sample/AuthoringTagHelpers/src/AuthoringTagHelpers/Views/_ViewImportsCopy.cshtml?highlight=3)]
[!code-cshtml[Main](../../../mvc/views/tag-helpers/authoring/sample/AuthoringTagHelpers/src/AuthoringTagHelpers/Views/_ViewImportsCopy.cshtml?highlight=3)]
If your project contains an `EmailTagHelper` with the default namespace (`AuthoringTagHelpers.TagHelpers.EmailTagHelper`), you can provide the fully qualified name (FQN) of the Tag Helper:
@ -75,7 +75,7 @@ If your project contains an `EmailTagHelper` with the default namespace (`Author
To add a Tag Helper to a view using an FQN, you first add the FQN (`AuthoringTagHelpers.TagHelpers.EmailTagHelper`), and then the assembly name (*AuthoringTagHelpers*). Most developers prefer to use the "\*" wildcard syntax. The wildcard syntax allows you to insert the wildcard character "\*" as the suffix in an FQN. For example, any of the following directives will bring in the `EmailTagHelper`:
```csharp
```cshtml
@addTagHelper AuthoringTagHelpers.TagHelpers.E*, AuthoringTagHelpers
@addTagHelper AuthoringTagHelpers.TagHelpers.Email*, AuthoringTagHelpers
```
@ -98,7 +98,7 @@ You can add a *_ViewImports.cshtml* to any view folder, and the view engine appl
You can disable a Tag Helper at the element level with the Tag Helper opt-out character ("!"). For example, `Email` validation is disabled in the `<span>` with the Tag Helper opt-out character:
```csharp
```cshtml
<!span asp-validation-for="Email" class="text-danger"></!span>
```
@ -110,7 +110,7 @@ You must apply the Tag Helper opt-out character to the opening and closing tag.
The `@tagHelperPrefix` directive allows you to specify a tag prefix string to enable Tag Helper support and to make Tag Helper usage explicit. For example, you could add the following markup to the *Views/_ViewImports.cshtml* file:
```html
```cshtml
@tagHelperPrefix th:
```
In the code image below, the Tag Helper prefix is set to `th:`, so only those elements using the prefix `th:` support Tag Helpers (Tag Helper-enabled elements have a distinctive font). The `<label>` and `<input>` elements have the Tag Helper prefix and are Tag Helper-enabled, while the `<span>` element does not.
@ -163,13 +163,13 @@ IntelliSense lists the properties and methods available to the model on the page
Tag Helpers attach to HTML elements in Razor views, while [HTML Helpers](http://stephenwalther.com/archive/2009/03/03/chapter-6-understanding-html-helpers) are invoked as methods interspersed with HTML in Razor views. Consider the following Razor markup, which creates an HTML label with the CSS class "caption":
```html
```cshtml
@Html.Label("FirstName", "First Name:", new {@class="caption"})
```
The at (`@`) symbol tells Razor this is the start of code. The next two parameters ("FirstName" and "First Name:") are strings, so [IntelliSense](https://docs.microsoft.com/visualstudio/ide/using-intellisense) can't help. The last argument:
```html
```cshtml
new {@class="caption"}
```
@ -189,7 +189,7 @@ IntelliSense helps you write the entire line. The `LabelTagHelper` also defaults
generates:
```html
```cshtml
<label class="caption" for="FirstName">First Name</label>
```
@ -199,7 +199,7 @@ The camel-cased to sentence-cased content is not used if you add content to the
generates:
```html
```cshtml
<label class="caption" for="FirstName">Name First</label>
```
@ -209,7 +209,7 @@ The following code image shows the Form portion of the *Views/Account/Register.c
The Visual Studio editor displays C# code with a grey background. For example, the `AntiForgeryToken` HTML Helper:
```html
```cshtml
@Html.AntiForgeryToken()
```

View File

@ -29,7 +29,7 @@ This tutorial assumes you have already installed the following:
* [Visual Studio](https://www.visualstudio.com)
* [ASP.NET Core](https://download.microsoft.com/download/F/6/E/F6ECBBCC-B02F-424E-8E03-D47E9FA631B7/DotNetCore.1.0.1-VS2015Tools.Preview2.0.3.exe) (runtime and tooling)
* [ASP.NET Core](https://www.microsoft.com/net/download/core) (runtime and tooling)
* [Git](https://git-scm.com/downloads) for Windows
@ -39,14 +39,16 @@ This tutorial assumes you have already installed the following:
2. From the **File** menu, select **New** > **Project**.
3. Select the **ASP.NET Web Application** project template. It appears under **Installed** > **Templates** > **Visual C#** > **Web**. Name the project `SampleWebAppDemo`. Select the **Create new Git respository** option and click **OK**.
3. Select the **ASP.NET Core Web Application** project template. It appears under **Installed** > **Templates** > **Visual C#** > **.NET Core**. Name the project `SampleWebAppDemo`. Select the **Create new Git respository** option and click **OK**.
![New Project dialog](azure-continuous-deployment/_static/01-new-project.png)
4. In the **New ASP.NET Project** dialog, select the ASP.NET Core **Empty** template, then click **OK**.
4. In the **New ASP.NET Core Project** dialog, select the ASP.NET Core **Empty** template, then click **OK**.
![New ASP.NET Project dialog](azure-continuous-deployment/_static/02-web-site-template.png)
>[!NOTE]
>Most recent release of .NET Core is 2.0
### Running the web app locally
@ -89,21 +91,17 @@ Git is a distributed version control system that you can use to deploy your Azur
1. Log into the [Azure Portal](https://portal.azure.com), if you're not already logged in.
2. Click **Browse**, located at the bottom of the navigation pane.
2. Click **App Services** to view a list of the app services associated with your Azure subscription.
3. Click **Web Apps** to view a list of the web apps associated with your Azure subscription.
3. Select the web app you created in the previous section of this tutorial.
4. Select the web app you created in the previous section of this tutorial.
4. In the **Deployment** blade, select **Deployment options** > **Choose Source** > **Local Git Repository**.
5. If the **Settings** blade is not shown, select **Settings** in the **Web App** blade.
![Settings blade: Deployment source blade: Choose source blade](azure-continuous-deployment/_static/deployment-options.png)
6. In the **Settings** blade, select **Deployment source** > **Choose Source** > **Local Git Repository**.
5. Click **OK**.
![Settings blade: Deployment source blade: Choose source blade](azure-continuous-deployment/_static/08-azure-localrepository.png)
7. Click **OK**.
8. If you have not previously set up deployment credentials for publishing a web app or other App Service app, set them up now:
6. If you have not previously set up deployment credentials for publishing a web app or other App Service app, set them up now:
* Click **Settings** > **Deployment credentials**. The **Set deployment credentials** blade will be displayed.
@ -111,9 +109,9 @@ Git is a distributed version control system that you can use to deploy your Azur
* Click **Save**.
9. In the **Web App** blade, click **Settings** > **Properties**. The URL of the remote Git repository that you'll deploy to is shown under **GIT URL**.
7. In the **Web App** blade, click **Settings** > **Properties**. The URL of the remote Git repository that you'll deploy to is shown under **GIT URL**.
10. Copy the **GIT URL** value for later use in the tutorial.
8. Copy the **GIT URL** value for later use in the tutorial.
![Azure Portal: application Properties blade](azure-continuous-deployment/_static/09-azure-giturl.png)
@ -189,7 +187,7 @@ In this section, you will create a local Git repository using Visual Studio and
You can verify that you successfully transferred the web app from your local environment to Azure. You'll see the listed successful deployment.
1. In the [Azure Portal](https://portal.azure.com), select your web app. Then, select **Settings** > **Continuous deployment**.
1. In the [Azure Portal](https://portal.azure.com), select your web app. Then, select **Deployment** > **Deployment options**.
![Azure Portal: Settings blade: Deployments blade showing successful deployment](azure-continuous-deployment/_static/13-verify-deployment.png)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 203 KiB

After

Width:  |  Height:  |  Size: 254 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View File

@ -16,7 +16,7 @@ uid: security/authorization/dependencyinjection
<a name="security-authorization-di"></a>
[Authorization handlers must be registered](policies.md#security-authorization-policies-based-handler-registration) in the service collection during configuration (using [dependency injection](../../fundamentals/dependency-injection.md#fundamentals-dependency-injection)).
[Authorization handlers must be registered](policies.md#handler-registration) in the service collection during configuration (using [dependency injection](../../fundamentals/dependency-injection.md#fundamentals-dependency-injection)).
Suppose you had a repository of rules you wanted to evaluate inside an authorization handler and that repository was registered in the service collection. Authorization will resolve and inject that into your constructor.