commit
677986b3a3
|
@ -20,7 +20,7 @@ Creating a multilingual website with ASP.NET Core will allow your site to reach
|
|||
|
||||
Internationalization involves [Globalization](https://docs.microsoft.com/dotnet/api/system.globalization) and [Localization](https://docs.microsoft.com/dotnet/standard/globalization-localization/localization). Globalization is the process of designing apps that support different cultures. Globalization adds support for input, display, and output of a defined set of language scripts that relate to specific geographic areas.
|
||||
|
||||
Localization is the process of adapting a globalized app, which you have already processed for localizability, to a particular culture/locale. For more information see **Globalization and localization terms** near the end of this document.
|
||||
Localization is the process of adapting a globalized app, which you have already processed for localizability, to a particular culture/locale. For more information see **Globalization and localization terms** near the end of this document.
|
||||
|
||||
App localization involves the following:
|
||||
|
||||
|
@ -32,8 +32,7 @@ App localization involves the following:
|
|||
|
||||
## Make the app's content localizable
|
||||
|
||||
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.
|
||||
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/Localization/Controllers/AboutController.cs)]
|
||||
|
||||
|
@ -302,7 +301,7 @@ The process of localizing your app also requires a basic understanding of releva
|
|||
|
||||
[Localizability](https://docs.microsoft.com/dotnet/standard/globalization-localization/localizability-review) is an intermediate process for verifying that a globalized app is ready for localization.
|
||||
|
||||
The [RFC 4646](https://www.ietf.org/rfc/rfc4646.txt) format for the culture name is "<languagecode2>-<country/regioncode2>", where <languagecode2> is the language code and <country/regioncode2> is the subculture code. For example, `es-CL` for Spanish (Chile), `en-US` for English (United States), and `en-AU` for English (Australia). [RFC 4646](https://www.ietf.org/rfc/rfc4646.txt) is a combination of an ISO 639 two-letter lowercase culture code associated with a language and an ISO 3166 two-letter uppercase subculture code associated with a country or region. See [Language Culture Name](https://msdn.microsoft.com/library/ee825488(v=cs.20).aspx).
|
||||
The [RFC 4646](https://www.ietf.org/rfc/rfc4646.txt) format for the culture name is `<languagecode2>-<country/regioncode2>`, where `<languagecode2>` is the language code and `<country/regioncode2>` is the subculture code. For example, `es-CL` for Spanish (Chile), `en-US` for English (United States), and `en-AU` for English (Australia). [RFC 4646](https://www.ietf.org/rfc/rfc4646.txt) is a combination of an ISO 639 two-letter lowercase culture code associated with a language and an ISO 3166 two-letter uppercase subculture code associated with a country or region. See [Language Culture Name](https://msdn.microsoft.com/library/ee825488(v=cs.20).aspx).
|
||||
|
||||
Internationalization is often abbreviated to "I18N". The abbreviation takes the first and last letters and the number of letters between them, so 18 stands for the number of letters between the first "I" and the last "N". The same applies to Globalization (G11N), and Localization (L10N).
|
||||
|
||||
|
|
|
@ -1,36 +1,23 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
|
||||
namespace FileUploadSample.Filters
|
||||
{
|
||||
#region snippet1
|
||||
#region snippet1
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
|
||||
public class DisableFormValueModelBindingAttribute : Attribute, IResourceFilter
|
||||
{
|
||||
public void OnResourceExecuting(ResourceExecutingContext context)
|
||||
{
|
||||
var formValueProviderFactory = context.ValueProviderFactories
|
||||
.OfType<FormValueProviderFactory>()
|
||||
.FirstOrDefault();
|
||||
if (formValueProviderFactory != null)
|
||||
{
|
||||
context.ValueProviderFactories.Remove(formValueProviderFactory);
|
||||
}
|
||||
|
||||
var jqueryFormValueProviderFactory = context.ValueProviderFactories
|
||||
.OfType<JQueryFormValueProviderFactory>()
|
||||
.FirstOrDefault();
|
||||
if (jqueryFormValueProviderFactory != null)
|
||||
{
|
||||
context.ValueProviderFactories.Remove(jqueryFormValueProviderFactory);
|
||||
}
|
||||
var factories = context.ValueProviderFactories;
|
||||
factories.RemoveType<FormValueProviderFactory>();
|
||||
factories.RemoveType<JQueryFormValueProviderFactory>();
|
||||
}
|
||||
|
||||
public void OnResourceExecuted(ResourceExecutedContext context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -24,6 +24,6 @@ The list below is sorted alphabetically.
|
|||
| [AspNet.Security.OpenIdConnect.Server (ASOS)](https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server) | Low-level/protocol-first OpenID Connect server framework for ASP.NET Core and OWIN/Katana |
|
||||
| [IdentityServer4](https://identityserver.io/) | OpenID Connect and OAuth 2.0 framework for ASP.NET Core - officially certified by the OpenID Foundation and under governance of the .NET Foundation |
|
||||
| [OpenIddict](https://github.com/openiddict/openiddict-core) | Easy-to-use OpenID Connect server for ASP.NET Core |
|
||||
| [PwdLess](https://github.com/pwdless/pwdless) | Simple, stateless, passwordless authentication for ASP.NET Core |
|
||||
| [Cierge](https://github.com/pwdless/Cierge) | Passwordless, drop-in OpenID Connect authentication |
|
||||
|
||||
To get your provider added here [edit this page](https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Faspnet%2FDocs%2Fedit%2Fmaster%2Faspnetcore%2Fsecurity%2Fauthentication%2Fcommunity.md).
|
||||
|
|
|
@ -5,7 +5,7 @@ description: Use Identity with an ASP.NET Core app
|
|||
keywords: ASP.NET Core,Identity,authorization,security
|
||||
ms.author: riande
|
||||
manager: wpickett
|
||||
ms.date: 12/15/2017
|
||||
ms.date: 01/02/2018
|
||||
ms.topic: article
|
||||
ms.assetid: cf119f21-1a2b-49a2-b052-547ccb66ee83
|
||||
ms.technology: aspnet
|
||||
|
@ -27,11 +27,20 @@ In this topic, you'll learn how to use ASP.NET Core Identity to add functionalit
|
|||
1. Create an ASP.NET Core Web Application project with Individual User Accounts.
|
||||
|
||||
# [Visual Studio](#tab/visual-studio)
|
||||
In Visual Studio, select **File** -> **New** -> **Project**. Select the **ASP.NET Web Application** from the **New Project** dialog box. Selecting an ASP.NET Core **Web Application(Model-View-Controller)** for ASP.NET Core 2.x with **Individual User Accounts** as the authentication method.
|
||||
In Visual Studio, select **File** -> **New** -> **Project**. Select **ASP.NET Core Web Application** and click **OK**.
|
||||
|
||||
Note: You must select **Individual User Accounts**.
|
||||
![New Project dialog](identity/_static/01-new-project.png)
|
||||
|
||||
Select an ASP.NET Core **Web Application (Model-View-Controller)** for ASP.NET Core 2.x, then select **Change Authentication**.
|
||||
|
||||
![New Project dialog](identity/_static/02-new-project.png)
|
||||
|
||||
A dialog appears offering authentication choices. Select **Individual User Accounts** and click **OK** to return to the previous dialog.
|
||||
|
||||
![New Project dialog](identity/_static/03-new-project-auth.png)
|
||||
|
||||
Selecting **Individual User Accounts** directs Visual Studio to create Models, ViewModels, Views, Controllers, and other assets required for authentication as part of the project template.
|
||||
|
||||
![New Project dialog](identity/_static/01-mvc_2.png)
|
||||
|
||||
# [.NET Core CLI](#tab/netcore-cli)
|
||||
If using the .NET Core CLI, create the new project using ``dotnet new mvc --auth Individual``. This command creates a new project with the same Identity template code Visual Studio creates.
|
||||
|
@ -72,7 +81,7 @@ In this topic, you'll learn how to use ASP.NET Core Identity to add functionalit
|
|||
|
||||
Launch the application and then click on the **Register** link.
|
||||
|
||||
If this is the first time you're performing this action, you may be required to run migrations. The application prompts you to **Apply Migrations**:
|
||||
If this is the first time you're performing this action, you may be required to run migrations. The application prompts you to **Apply Migrations**. Refresh the page if needed.
|
||||
|
||||
![Apply Migrations Web Page](identity/_static/apply-migrations.png)
|
||||
|
||||
|
@ -95,9 +104,9 @@ In this topic, you'll learn how to use ASP.NET Core Identity to add functionalit
|
|||
|
||||
Users can sign in by clicking the **Log in** link at the top of the site, or they may be navigated to the Login page if they attempt to access a part of the site that requires authorization. When the user submits the form on the Login page, the ``AccountController`` ``Login`` action is called.
|
||||
|
||||
[!code-csharp[Main](identity/sample/src/ASPNET-IdentityDemo/Controllers/AccountController.cs?name=snippet_login&highlight=13-14)]
|
||||
|
||||
The ``Login`` action calls ``PasswordSignInAsync`` on the ``_signInManager`` object (provided to ``AccountController`` by dependency injection).
|
||||
|
||||
[!code-csharp[Main](identity/sample/src/ASPNET-IdentityDemo/Controllers/AccountController.cs?name=snippet_login&highlight=13-14)]
|
||||
|
||||
The base ``Controller`` class exposes a ``User`` property that you can access from controller methods. For instance, you can enumerate `User.Claims` and make authorization decisions. For more information, see [Authorization](xref:security/authorization/index).
|
||||
|
||||
|
@ -135,6 +144,35 @@ In this topic, you'll learn how to use ASP.NET Core Identity to add functionalit
|
|||
|
||||
Expand the database and its **Tables**, then right-click the **dbo.AspNetUsers** table and select **View Data**.
|
||||
|
||||
8. Verify Identity works
|
||||
|
||||
The default *ASP.NET Core Web Application* project template allows users to access any action in the application without having to login. To verify that ASP.NET Identity works, add an`[Authorize]` attribute to the `About` action of the `Home` Controller.
|
||||
|
||||
```cs
|
||||
[Authorize]
|
||||
public IActionResult About()
|
||||
{
|
||||
ViewData["Message"] = "Your application description page.";
|
||||
return View();
|
||||
}
|
||||
```
|
||||
|
||||
# [Visual Studio](#tab/visualstudio)
|
||||
|
||||
Run the project using **Ctrl** + **F5** and navigate to the **About** page. Only authenticated users may access the **About** page now, so ASP.NET redirects you to the login page to login or register.
|
||||
|
||||
# [.NET Core CLI](#tab/netcore-cli)
|
||||
|
||||
Open a command window and navigate to the project's root directory containing the `.csproj` file. Run the `dotnet run` command to run the app:
|
||||
|
||||
```cs
|
||||
dotnet run
|
||||
```
|
||||
|
||||
Browse the URL specified in the output from the `dotnet run` command. The URL should point to `localhost` with a generated port number. Navigate to the **About** page. Only authenticated users may access the **About** page now, so ASP.NET redirects you to the login page to login or register.
|
||||
|
||||
---
|
||||
|
||||
## Identity Components
|
||||
|
||||
The primary reference assembly for the Identity system is `Microsoft.AspNetCore.Identity`. This package contains the core set of interfaces for ASP.NET Core Identity, and is included by `Microsoft.AspNetCore.Identity.EntityFrameworkCore`.
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 118 KiB |
Binary file not shown.
After Width: | Height: | Size: 113 KiB |
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
Binary file not shown.
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
Loading…
Reference in New Issue