NopCommerce 中的 UrlRewriting 问题

发布于 2024-10-06 01:04:49 字数 3189 浏览 0 评论 0原文

我尝试在 NopCommerce 中进行更改,以在地址栏中包含语言,但我确实不知道问题是什么。

当我禁用 UrlRewriting 时,一切工作正常,当我启用它时,当我使用默认语言时,一切工作正常,当我转到另一种非默认语言时,我遇到了问题。

我有两部分代码用于默认语言,对于其他语言,

我稍微更改了代码,因此主函数现在在语言之间进行选择:

    public static string GetCategoryUrl(Category category, int languageId)
    {
        if (category == null)
            throw new ArgumentNullException("category");
        string seName = GetSEName(category.SEName);

        if (String.IsNullOrEmpty(seName))
        {
            var categoryLocalized = CategoryManager.GetCategoryLocalizedByCategoryIdAndLanguageId(category.CategoryId, languageId);
            if (categoryLocalized != null)
            {
                seName = GetSEName(categoryLocalized.Name);
            }
            else
            {
            seName = GetSEName(category.Name);
            }
        }            

        int defaultLanguage = Convert.ToInt32(SettingManager.GetSettingValue("Localization.DefaultLanguageID"));
        string url = String.Empty;

        string url2 = String.Empty;

        //***for default language***
        if (languageId == defaultLanguage)
        {
            url2 = SEOHelper.EnableUrlRewriting ? SettingManager.GetSettingValue("SEO.Category.UrlRewriteFormat") : "{0}Category.aspx?CategoryID={1}";
            url = string.Format(url2, CommonHelper.GetStoreLocation(), category.CategoryId, seName);
        }

        //***for other languages***
        else
        {
            url2 = SEOHelper.EnableUrlRewriting ? SettingManager.GetSettingValue("SEO.Category.UrlRewriteFormat2") : "{0}Category.aspx?Language={1}&CategoryID={2}";
            url = string.Format(url2, CommonHelper.GetStoreLocation(), GetLocaleSubFolder(languageId), category.CategoryId, seName);
        }
        return url.ToLowerInvariant();
    }

对于默认语言,我也有: 对于 SEO.Category.UrlRewriteFormat 我在数据库中有默认语言:{0}c{1}/{2}

在 UrlRewriting.config 中我有以下默认语言规则:

没有网址重写我上面的链接看起来像 www.nopcomerce.com/category.aspx?categoryid=10

当我以默认语言转到类别时,我的链接看起来像 www.nopcomerce.com/c10/somecategory

对于其他语言:

对于 SEO.Category.UrlRewriteFormat2,我在其他语言的数据库中有:{0 {1}/c{2}/{3}

以及我拥有的其他语言

对于其他语言,没有 url 重写的链接看起来像 www.nopcomerce.com/category.aspx?language=de&categoryid=10

当我去例如德语的同一类别时,我会 www.nopcomerce.com/de/c10/somecategorylocalizedingerman

现在我知道该页面工作正常,正如我之前所说,因为当我在 NopCommerce 中禁用所有语言的 UrlRewriting 时工作正常。我可以在类别、产品和整个门户之间更改语言,对于每种语言都没有问题。

但是,当我启用 UrlRewriting 时,默认语言的类别链接工作正常(www.nopcomerce.com/c10/somecategory),但是当我单击其他语言的链接时,每次我单击任何链接时,例如其他语言的类别链接,显示的内容来自默认页面(就像它将我重定向到那里),但我看到我想要使用某种语言的链接已写在地址栏 (www.nopcomerce.com/de/c10/somecategorylocalizedingerman)。

我尝试了一切,但我确实不知道问题出在哪里。怎么了?

我也尝试在 NopCommerce 论坛中寻求帮助,但那里没有任何帮助。

你可以阅读我开始写的这个问题,直到这部分我现在不知道什么似乎是一个问题。

http://www.nopcommerce.com /boards/t/1039/seo-and-multilingual-pages.aspx?p=1

感谢您提前提供的所有帮助。

I try to make changes in NopCommerce to include language in addreess bar I do knot know what seem to be problem.

When I disable UrlRewriting everything works fine, when I enable it, when I'm on default language everything works fine when I go to another language that is not default, I have the problems.

I have two parts of code for default languge and for other languages

I change a little bit a code, so main function now choose between languages:

    public static string GetCategoryUrl(Category category, int languageId)
    {
        if (category == null)
            throw new ArgumentNullException("category");
        string seName = GetSEName(category.SEName);

        if (String.IsNullOrEmpty(seName))
        {
            var categoryLocalized = CategoryManager.GetCategoryLocalizedByCategoryIdAndLanguageId(category.CategoryId, languageId);
            if (categoryLocalized != null)
            {
                seName = GetSEName(categoryLocalized.Name);
            }
            else
            {
            seName = GetSEName(category.Name);
            }
        }            

        int defaultLanguage = Convert.ToInt32(SettingManager.GetSettingValue("Localization.DefaultLanguageID"));
        string url = String.Empty;

        string url2 = String.Empty;

        //***for default language***
        if (languageId == defaultLanguage)
        {
            url2 = SEOHelper.EnableUrlRewriting ? SettingManager.GetSettingValue("SEO.Category.UrlRewriteFormat") : "{0}Category.aspx?CategoryID={1}";
            url = string.Format(url2, CommonHelper.GetStoreLocation(), category.CategoryId, seName);
        }

        //***for other languages***
        else
        {
            url2 = SEOHelper.EnableUrlRewriting ? SettingManager.GetSettingValue("SEO.Category.UrlRewriteFormat2") : "{0}Category.aspx?Language={1}&CategoryID={2}";
            url = string.Format(url2, CommonHelper.GetStoreLocation(), GetLocaleSubFolder(languageId), category.CategoryId, seName);
        }
        return url.ToLowerInvariant();
    }

For default language I have also:
For SEO.Category.UrlRewriteFormat I have in database for default language: {0}c{1}/{2}

In UrlRewriting.config I have this rules for default language:

with no url rewriting my link above look like
www.nopcomerce.com/category.aspx?categoryid=10

When I go to category in default language my link look like
www.nopcomerce.com/c10/somecategory

For other languages:

For SEO.Category.UrlRewriteFormat2 I have in database for other languages: {0}{1}/c{2}/{3}

and for other languages I have

the link with no url rewrithing for other language look like
www.nopcomerce.com/category.aspx?language=de&categoryid=10

And when I go to for example in same category in German I will have
www.nopcomerce.com/de/c10/somecategorylocalizedingerman

Now I know that page works fine, as I say before, because when I disable UrlRewriting in NopCommerce all pages in all languages works fine. I can change language between categories, products and entire portal with no problem on every language.

But when I enable UrlRewriting, the links for category's in default language works fine (www.nopcomerce.com/c10/somecategory), but when i click on link's in other languages, every time I click any link, for example some link for category in other language, the content that is show is from default page (like it redirect me there) but I see that the link that I want to go in some language is written in address bar (www.nopcomerce.com/de/c10/somecategorylocalizedingerman).

I try everything but I do knot know what's to the problem. What is wrong?

I also try to ask for help in NopCommerce forum but there is no help from there.

You can read abot this problem where I started to write until this part where I do not now what seem's to be a problem.

http://www.nopcommerce.com/boards/t/1039/seo-and-multilingual-pages.aspx?p=1

Thanks for every help in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

×纯※雪 2024-10-13 01:04:54

经过几天的折磨和几个小时的折磨后,我放弃了一件事,那就是链接将如我所愿。

我从来没有成功地做到过语言链接,除了默认链接之外,看起来像:

nopcommerce.com /国家/类别/类别名称

我设法实现的最接近的是将我链接到

nopcommerce.com /类别/国家/类别名称。

我还设法制作了与常规超链接不同的经典 ImageButton 链接以及我偶然发现的一个有趣问题的链接。

NopCommerce 使用 cookie 来更改语言。

我找到了 cookie 的名称,然后他将其写入 NopContext.Current.WorkingLanguage。

以类似的方式,我还创建了一个 javascript 函数 setCookie ()

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
        ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}

,它在 cookie 中创建所选语言的日志值,并在用户单击所选语言的标志时激活。

例如

string coockie = String.Format("javascript:setCookie('{0}','{1}','{2}');", "Nop.CustomerLanguage", language.LanguageId.ToString(), new TimeSpan(365, 0, 0, 0, 0));
hpLanguage.Attributes.Add("onclick", coockie);

,现在我们来到了有趣的部分,问题发生了,但我不清楚为什么会发生。

假设我们有德语和英语

当我第一次单击德语的标志时,地址栏中会显示一个指向德语的链接,但内容仍然是英语。仅当第二次(再次)我单击德语中的标志时,页面内容才会切换为德语。

我不明白为什么这种事现在发生在我身上?

After several days of torture and the many hours I gave up one thing, and it is that links will be as I want.

I never managed to do that links for languages, other than the default link, looks like:

nopcommerce.com / country / category / name-of-category

The closest I've managed to achieve is to link me look

nopcommerce.com / category / country / name-of-category.

I also managed to make the links that we are not classic ImageButton than regular hyperlink and links that I stumbled on an interesting problem.

NopCommerce use cookie to change the language.

I found the name of the cookie, and as he writes it into NopContext.Current.WorkingLanguage.

In a similar way, I also created a javascript function setCookie ()

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
        ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}

which creates a log value of the selected language in the cookie and which activates when a user clicks on the flag of the selected language.

eg

string coockie = String.Format("javascript:setCookie('{0}','{1}','{2}');", "Nop.CustomerLanguage", language.LanguageId.ToString(), new TimeSpan(365, 0, 0, 0, 0));
hpLanguage.Attributes.Add("onclick", coockie);

And now we come to the interesting part where the problem occurs and it is not clear to me why it happens.

Suppose we have German and English

When I first click on the flag of the German language, in the address bar shows me a link to the German language, but the content is still in English. Only when the second time, (again) I click the flag in the German language the content of the page is switch to German language.

I do not understand why this is happening now to me?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文