2.7 bug in IDLess URLS'

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 年 前
If the product name contains a % sign you get an error

E.g. Black Shoes 100% leather

gives you

Server Error in '/' Application.
--------------------------------------------------------------------------------

HTTP Error 400 - Bad Request.
11 年 前
This is a client side error (eg. a bad request) because of the percentage sign, this will probably work if you URL encode the percentage sign as %25
11 年 前
keesjan wrote:
This is a client side error (eg. a bad request) because of the percentage sign, this will probably work if you URL encode the percentage sign as %25


Thanks for the fast response.

How do I URL encode?

This error occurs using nop 2.7 out of the box with a product name with a % sign.

Shouldn't the source code handle URL encoding?

Changing the name of the product is not an option unfortunately.
11 年 前
Everything works fine. When you created a product and do not enter "sename" on seo tab, then it's automatically generated. But % char is not allowed for sename out of the box. Maybe you have a custom version of your "GetSeName" method of SeoExtensions class.

If you have it, then you can always set nay sename property you want on SEO tab.
11 年 前
a.m. wrote:
Everything works fine. When you created a product and do not enter "sename" on seo tab, then it's automatically generated. But % char is not allowed for sename out of the box. Maybe you have a custom version of your "GetSeName" method of SeoExtensions class.

If you have it, then you can always set nay sename property you want on SEO tab.


I've realised it's the "Search engine friendly page name:" that causes the issue. If it contains a "%" sign you get this error

I have the "Smart SEO" plugin from "nop-templates" installed which has auto populated this field for all products.
11 年 前
Is there a fix that could strip out invalid characters? Otherwise I'll have to manually remove invalid chars from each products "Search Engine Friendly Page Name"
11 年 前
Fixed.

Libraries\Nop.Services\Seo\UrlRecordService.cs
Method: FindSlug (ln 149)

Add
slug = HttpUtility.UrlEncode(slug);

so full method is

 public virtual string FindSlug(int entityId, string entityName,int languageId)
        {
            string key = string.Format(URLRECORD_BY_ID_NAME_LANGUAGE_KEY, entityId, entityName, languageId);
            return _cacheManager.Get(key, () =>
            {
                var query = from ur in _urlRecordRepository.Table
                            where ur.EntityId == entityId &&
                            ur.EntityName == entityName &&
                            ur.LanguageId == languageId
                            select ur.Slug;
                var slug = query.FirstOrDefault();
                //little hack here. nulls aren't cacheable so set it to ""
                if (slug == null)
                    slug = "";

               slug = HttpUtility.UrlEncode(slug);
                return slug;
            });
        }


Slug should always be URL encoded as it is used as part of URL

Hope this helps someone

Darren
11 年 前
Actually this doesn't work. Still investigating
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.