简体   繁体   中英

ASP.NET boilerplate localization

In ASP.NET Boilerplate I am changing language like

<a href="/AbpLocalization/ChangeCulture?cultureName=en">English</a>

It works properly on my local machine, but not on test server.
Also when I'm clicking it locally, sometimes there is abp.message.error with null content.

I have a few questions about that:

1) What is this URL (/AbpLocalization...), looks lika a controller, but there is no such thing in my code?

2) How can I find and debug it?

3) What may happen on another server that crashes it (on test server clicking button reloads state, but does not change language)

Solved! What caused the problem was the fact, that the database on test server did not have one table that was in local database, and what's more important: this table was included in model transferred through Entity Framework to database. After adding table to test server everything works fine.

ASP.NET Boilerplate is an application framework built from modules, one of them being Localization module. Since it's open source you can change default behaviors, although I should not recommend doing it without really good reason.

Localization is part of the core package and it's located here: GitHub

I recommend you to use documentation and configure it to your needs. You can find localization documentation here: documentation .

And lastly, you should check your running configuration in the test environment, which is possibly faulted in some way. Another reason for error may be an issue with your ABP version.

AbpLocalizationController is located here in source code

src/Abp.AspNetCore/AspNetCore/Mvc/Controllers/AbpLocalizationController.cs

And this is change culture code:

public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "")
        {
            if (!GlobalizationHelper.IsValidCultureCode(cultureName))
            {
                throw new AbpException("Unknown language: " + cultureName + ". It must be a valid culture!");
            }

            var cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(cultureName, cultureName));

            Response.Cookies.Append(
                CookieRequestCultureProvider.DefaultCookieName,
                cookieValue,
                new CookieOptions {Expires = Clock.Now.AddYears(2)}
            );

            if (AbpSession.UserId.HasValue)
            {
                SettingManager.ChangeSettingForUser(
                    AbpSession.ToUserIdentifier(),
                    LocalizationSettingNames.DefaultLanguage,
                    cultureName
                );
            }

            if (Request.IsAjaxRequest())
            {
                return Json(new AjaxResponse());
            }

            if (!string.IsNullOrWhiteSpace(returnUrl) && AbpUrlHelper.IsLocalUrl(Request, returnUrl))
            {
                return Redirect(returnUrl);
            }

            return Redirect("/"); //TODO: Go to app root
}

https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.AspNetCore/AspNetCore/Mvc/Controllers/AbpLocalizationController.cs

If you want to debug this code, fork the project from github repo and add it to your solution. Replace your abp dll references with this local project references.

Meanwhile you didn't mention what the error say. To learn it check out website logs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM