Update live with current master (#4426)

* Add PO localization doc

* More edits

* Updates TaskCache to Task

Since [TaskCache](https://github.com/aspnet/Common/issues/238) was removed this updates the samples to use `Task.CompletedTask` instead

* More edits

* More edits

* Change code snippet type from C# to CSHTML

* Add missing snippet types

* React to feedback

* Add support disclaimer

* UE pass on Publishing to IIS topic

* Drop literal_block comments and fix a few code blocks

* Fix demo code for AddAuthentication.AddCookie

In .Net Core 2.0 using the code as supplied results in an exception, the fix is to pass the scheme name when calling AddCookie.

Fails:
services.AddAuthentication("MyCookieAuthenticationScheme")
        .AddCookie

Works:
Fix demo code for services.AddAuthentication.AddCookie
services.AddAuthentication("MyCookieAuthenticationScheme")
        .AddCookie("MyCookieAuthenticationScheme",

* React to feedback

* Fix one

* Convert title to sentence case

* Add missing param to AddCookie call

* React to feedback
pull/4755/head^2
Rick Anderson 2017-09-27 14:41:18 -07:00 committed by GitHub
parent 28797c2751
commit 96ce03d509
180 changed files with 961 additions and 375 deletions

View File

@ -26,19 +26,15 @@ In addition to debugging your own code, it is possible to debug directly into Mi
Then add a link to [symbolsource.org](http://symbolsource.org) for downloading the source and symbols. Go to the **Symbols** tab of the menu above and add the following as a symbol location:
<!-- literal_block {"names": [], "classes": [], "dupnames": [], "xml:space": "preserve", "backrefs": [], "ids": []} -->
````
```
http://srv.symbolsource.org/pdb/Public
````
```
In addition, make sure that the cache directory has a short name; otherwise the file names can get too long which will cause the symbols to not load. A sample path is:
<!-- literal_block {"names": [], "classes": [], "dupnames": [], "xml:space": "preserve", "backrefs": [], "ids": []} -->
````
```
C:\SymCache
````
```
The settings should look similar to this:

View File

@ -34,9 +34,7 @@ WebHooks is a pattern which means that it varies how it is used from service to
Typically the HTTP POST request contains a JSON object or HTML form data determined by the WebHook sender including information about the event causing the WebHook to trigger. For example, an example of a WebHook POST request body from [GitHub](http://www.github.com/) looks like this as a result of a new issue being opened in a particular repository:
<!-- literal_block {"names": [], "classes": [], "dupnames": [], "xml:space": "preserve", "backrefs": [], "ids": []} -->
````javascript
```json
{
"action": "opened",
"issue": {
@ -60,7 +58,7 @@ Typically the HTTP POST request contains a JSON object or HTML form data determi
...
}
}
````
```
To ensure that the WebHook is indeed from the intended sender, the POST request is secured in some way and then verified by the receiver. For example, [GitHub WebHooks](https://developer.github.com/webhooks/) includes an *X-Hub-Signature* HTTP header with a hash of the request body which is checked by the receiver implementation so you don't have to worry about it.

View File

@ -34,8 +34,6 @@ When a handler is called, it gets a [WebHookHandlerContext](https://github.com/a
The type of the data is typically JSON or HTML form data, but it is possible to cast to a more specific type if desired. For example, the custom WebHooks generated by ASP.NET WebHooks can be cast to the type [CustomNotifications](https://github.com/aspnet/WebHooks/blob/master/src/Microsoft.AspNet.WebHooks.Receivers.Custom/WebHooks/CustomNotifications.cs) as follows:
<!-- literal_block {"names": [], "classes": [], "dupnames": [], "xml:space": "preserve", "backrefs": [], "ids": []} -->
```csharp
public class MyWebHookHandler : WebHookHandler
{
@ -64,8 +62,6 @@ If the processing takes longer, or is better handled separately then the [WebHoo
An outline of a [WebHookQueueHandler](https://github.com/aspnet/WebHooks/blob/master/src/Microsoft.AspNet.WebHooks.Receivers/WebHooks/WebHookQueueHandler.cs) implementation is provided here:
<!-- literal_block {"names": [], "classes": [], "dupnames": [], "xml:space": "preserve", "backrefs": [], "ids": []} -->
```csharp
public class QueueHandler : WebHookQueueHandler
{

View File

@ -26,8 +26,6 @@ By installing Microsoft ASP.NET WebHooks you get a general WebHook controller wh
The URI of this controller is the WebHook URI that you register with the service and is of the form:
<!-- literal_block {"names": [], "classes": [], "dupnames": [], "xml:space": "preserve", "backrefs": [], "ids": []} -->
```
https://<host>/api/webhooks/incoming/<receiver>/{id}
```
@ -38,8 +36,6 @@ The *<receiver>* component is the name of the receiver, for example *github* or
The *{id}* is an optional identifier which can be used to identify a particular WebHook receiver configuration. This can be used to register N WebHooks with a particular receiver. For example, the following three URIs can be used to register for three independent WebHooks:
<!-- literal_block {"names": [], "classes": [], "dupnames": [], "xml:space": "preserve", "backrefs": [], "ids": []} -->
```
https://<host>/api/webhooks/incoming/github
https://<host>/api/webhooks/incoming/github/12345
@ -62,16 +58,12 @@ WebHook Receivers are configured through the [IWebHookReceiverConfig](https://gi
The format for Application Setting keys is as follows:
<!-- literal_block {"names": [], "classes": [], "dupnames": [], "xml:space": "preserve", "backrefs": [], "ids": []} -->
```
MS_WebHookReceiverSecret_<receiver>
````
```
The value is a comma-separated list of values matching the *{id}* values for which WebHooks have been registered, for example:
<!-- literal_block {"names": [], "classes": [], "dupnames": [], "xml:space": "preserve", "backrefs": [], "ids": []} -->
```
MS_WebHookReceiverSecret_GitHub = <secret1>, 12345=<secret2>, 54321=<secret3>
```
@ -80,8 +72,6 @@ MS_WebHookReceiverSecret_GitHub = <secret1>, 12345=<secret2>, 54321=<secret3>
WebHook Receivers are initialized by registering them, typically in the *WebApiConfig* static class, for example:
<!-- literal_block {"names": [], "classes": [], "dupnames": [], "xml:space": "preserve", "backrefs": [], "ids": []} -->
```csharp
namespace WebHookReceivers
{

View File

@ -74,8 +74,6 @@ You can use [globbing patterns](#globbing-patterns) when specifying files to emb
When creating an `EmbeddedFileProvider`, pass the assembly it will read to its constructor.
<!-- literal_block {"ids": [], "names": [], "highlight_args": {}, "backrefs": [], "dupnames": [], "linenos": false, "classes": [], "xml:space": "preserve", "language": "c#"} -->
```csharp
var embeddedProvider = new EmbeddedFileProvider(Assembly.GetEntryAssembly());
```

View File

@ -35,41 +35,41 @@ App localization involves the following:
Introduced in ASP.NET Core, `IStringLocalizer` and `IStringLocalizer<T>` were architected to improve productivity when developing localized apps. `IStringLocalizer` uses the [ResourceManager](https://docs.microsoft.com/dotnet/api/system.resources.resourcemanager) and [ResourceReader](https://docs.microsoft.com/dotnet/api/system.resources.resourcereader) to provide culture-specific resources at run time. The simple interface has an indexer and an `IEnumerable` for returning localized strings. `IStringLocalizer` doesn't require you to store the default language strings in a resource file. You can develop an app
targeted for localization and not need to create resource files early in development. The code below shows how to wrap the string "About Title" for localization.
[!code-csharp[Main](localization/sample/Controllers/AboutController.cs)]
[!code-csharp[Main](localization/sample/Localization/Controllers/AboutController.cs)]
In the code above, the `IStringLocalizer<T>` implementation comes from [Dependency Injection](dependency-injection.md). If the localized value of "About Title" is not found, then the indexer key is returned, that is, the string "About Title". You can leave the default language literal strings in the app and wrap them in the localizer, so that you can focus on developing the app. You develop your app with your default language and prepare it for the localization step without first creating a default resource file. Alternatively, you can use the traditional approach and provide a key to retrieve the default language string. For many developers the new workflow of not having a default language *.resx* file and simply wrapping the string literals can reduce the overhead of localizing an app. Other developers will prefer the traditional work flow as it can make it easier to work with longer string literals and make it easier to update localized strings.
Use the `IHtmlLocalizer<T>` implementation for resources that contain HTML. `IHtmlLocalizer` HTML encodes arguments that are formatted in the resource string, but not the resource string. In the sample highlighted below, only the value of `name` parameter is HTML encoded.
[!code-csharp[Main](../fundamentals/localization/sample/Controllers/BookController.cs?highlight=3,5,20&start=1&end=24)]
[!code-csharp[Main](../fundamentals/localization/sample/Localization/Controllers/BookController.cs?highlight=3,5,20&start=1&end=24)]
Note: You generally want to only localize text and not HTML.
At the lowest level, you can get `IStringLocalizerFactory` out of [Dependency Injection](dependency-injection.md):
[!code-csharp[Main](localization/sample/Controllers/TestController.cs?start=9&end=26&highlight=7-13)]
[!code-csharp[Main](localization/sample/Localization/Controllers/TestController.cs?start=9&end=26&highlight=7-13)]
The code above demonstrates each of the two factory create methods.
You can partition your localized strings by controller, area, or have just one container. In the sample app, a dummy class named `SharedResource` is used for shared resources.
[!code-csharp[Main](localization/sample/Resources/SharedResource.cs)]
[!code-csharp[Main](localization/sample/Localization/Resources/SharedResource.cs)]
Some developers use the `Startup` class to contain global or shared strings. In the sample below, the `InfoController` and the `SharedResource` localizers are used:
[!code-csharp[Main](localization/sample/Controllers/InfoController.cs?range=9-26)]
[!code-csharp[Main](localization/sample/Localization/Controllers/InfoController.cs?range=9-26)]
## View localization
The `IViewLocalizer` service provides localized strings for a [view](https://docs.microsoft.com/aspnet/core). The `ViewLocalizer` class implements this interface and finds the resource location from the view file path. The following code shows how to use the default implementation of `IViewLocalizer`:
[!code-HTML[Main](localization/sample/Views/Home/About.cshtml)]
[!code-HTML[Main](localization/sample/Localization/Views/Home/About.cshtml)]
The default implementation of `IViewLocalizer` finds the resource file based on the view's file name. There is no option to use a global shared resource file. `ViewLocalizer` implements the localizer using `IHtmlLocalizer`, so Razor doesn't HTML encode the localized string. You can parameterize resource strings and `IViewLocalizer` will HTML encode the parameters, but not the resource string. Consider the following Razor markup:
```HTML
```cshtml
@Localizer["<i>Hello</i> <b>{0}!</b>", UserManager.GetUserName(User)]
```
```
A French resource file could contain the following:
@ -85,7 +85,7 @@ Notes:
To use a shared resource file in a view, inject `IHtmlLocalizer<T>`:
[!code-HTML[Main](../fundamentals/localization/sample/Views/Test/About.cshtml?highlight=5,12)]
[!code-HTML[Main](../fundamentals/localization/sample/Localization/Views/Test/About.cshtml?highlight=5,12)]
## DataAnnotations localization
@ -94,7 +94,7 @@ DataAnnotations error messages are localized with `IStringLocalizer<T>`. Using t
* Resources/ViewModels.Account.RegisterViewModel.fr.resx
* Resources/ViewModels/Account/RegisterViewModel.fr.resx
[!code-csharp[Main](localization/sample/ViewModels/Account/RegisterViewModel.cs?start=9&end=26)]
[!code-csharp[Main](localization/sample/Localization/ViewModels/Account/RegisterViewModel.cs?start=9&end=26)]
In ASP.NET Core MVC 1.1.0 and higher, non-validation attributes are localized. ASP.NET Core MVC 1.0 does **not** look up localized strings for non-validation attributes.
@ -103,7 +103,7 @@ In ASP.NET Core MVC 1.1.0 and higher, non-validation attributes are localized. A
The following code shows how to use one resource string for validation attributes with multiple classes:
```
```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
@ -187,7 +187,7 @@ Each language and culture combination (other than the default language) requires
Localization is configured in the `ConfigureServices` method:
[!code-csharp[Main](localization/sample/Program.cs?name=snippet1)]
[!code-csharp[Main](localization/sample/Localization/Program.cs?name=snippet1)]
* `AddLocalization` Adds the localization services to the services container. The code above also sets the resources path to "Resources".
@ -199,7 +199,7 @@ Localization is configured in the `ConfigureServices` method:
The current culture on a request is set in the localization [Middleware](middleware.md). The localization middleware is enabled in the `Configure` method of *Program.cs* file. Note, the localization middleware must be configured before any middleware which might check the request culture (for example, `app.UseMvcWithDefaultRoute()`).
[!code-csharp[Main](localization/sample/Program.cs?name=snippet2)]
[!code-csharp[Main](localization/sample/Localization/Program.cs?name=snippet2)]
`UseRequestLocalization` initializes a `RequestLocalizationOptions` object. On every request the list of `RequestCultureProvider` in the `RequestLocalizationOptions` is enumerated and the first provider that can successfully determine the request culture is used. The default providers come from the `RequestLocalizationOptions` class:
@ -284,15 +284,15 @@ Use `RequestLocalizationOptions` to add or remove localization providers.
This sample **Localization.StarterWeb** project on [GitHub](https://github.com/aspnet/entropy) contains UI to set the `Culture`. The *Views/Shared/_SelectLanguagePartial.cshtml* file allows you to select the culture from the list of supported cultures:
[!code-HTML[Main](localization/sample/Views/Shared/_SelectLanguagePartial.cshtml)]
[!code-HTML[Main](localization/sample/Localization/Views/Shared/_SelectLanguagePartial.cshtml)]
The *Views/Shared/_SelectLanguagePartial.cshtml* file is added to the `footer` section of the layout file so it will be available to all views:
[!code-HTML[Main](localization/sample/Views/Shared/_Layout.cshtml?range=43-56&highlight=10)]
[!code-HTML[Main](localization/sample/Localization/Views/Shared/_Layout.cshtml?range=43-56&highlight=10)]
The `SetLanguage` method sets the culture cookie.
[!code-csharp[Main](localization/sample/Controllers/HomeController.cs?range=57-67)]
[!code-csharp[Main](localization/sample/Localization/Controllers/HomeController.cs?range=57-67)]
You can't plug in the *_SelectLanguagePartial.cshtml* to sample code for this project. The **Localization.StarterWeb** project on [GitHub](https://github.com/aspnet/entropy) has code to flow the `RequestLocalizationOptions` to a Razor partial through the [Dependency Injection](dependency-injection.md) container.
@ -320,4 +320,4 @@ Terms:
* [Localization.StarterWeb project](https://github.com/aspnet/entropy) used in the article.
* [Resource Files in Visual Studio](https://docs.microsoft.com/cpp/windows/resource-files-visual-studio)
* [Resources in .resx Files](https://docs.microsoft.com/dotnet/framework/resources/working-with-resx-files-programmatically)
* [Resources in .resx Files](https://docs.microsoft.com/dotnet/framework/resources/working-with-resx-files-programmatically)

Some files were not shown because too many files have changed in this diff Show More