开发者

Problem with UrlRewriting in NopCommerce

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 UrlRewri开发者_开发技巧ting, 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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜