I rephrase another question I asked earlier.
I have a basic C# Asp.net MVC 5 application. I create an account through the following code (provided by the template in Vs 2013)
protected async Task<bool> CreateAccountAndAddRoleAsync(UserManager<ApplicationUser> userManager, ApplicationUser user, string password, string role)
{
var result = await userManager.CreateAsync(user, password);
if (result.Succeeded)
{
try
{
var roleResult = await userManager.AddToRoleAsync(user.Id, role);
if (roleResult.Succeeded)
{
//await SignInAsync(userManager, user, isPersistent: false);
return true;
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
AddErrors(result);
return false;
}
protected void AddErrors(IdentityResult result)
{
foreach (var error in result.Errors)
{
ModelState.AddModelError("", error);
}
}
The problem is that when the username is already taken (or any other error message), the messages are in English. Such as
Name xxx is already taken
Instead of
L'identifiant xxx est déjà utilisé
The problem is that the message is provided by the framework with
var result = await userManager.CreateAsync(user, password);
And the AddErrors(result);
enumerates the messages (in english) to display them to the user. How can I modify the messages?
I changed the culture in the webconfig file with
<globalization uiCulture="fr-FR" culture="fr-FR" />
But I still have an English message. In fact, the real problem is that I can't change the message provided by the framework even if I wanted another message in English.
Does anyone know how to change the message provided by the IdentityResult
?
Do not forget to install your language package from nuget for example:
Install-Package Microsoft.AspNet.Identity.Core.ru
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With