#Url.Content not encoding text - ASP.NET MVC with Razor - asp.net-mvc-3

I need to build an url like this: /products/myproductdescription/5; it works except when the product description contains a "/".
I build the link with razor in this way:
#product.Description
I thought that using #product.Description would encode the description, but I get a link with the "/" if it is present in the description.
I tried this way also:
#product.Description
but the result is the same ...
Someone can tell me why that part of the link is not encoded?
Thank you.

You should avoid using special characters in the path portion of an url. You could use slugs and replace all dangerous characters. Here's for example how that's done on StackOverflow with the question titles in the url. In this case in order to be able to uniquely identify the resource always use an id. The description could only be used for SEO purposes.

Related

adding tracking parameter is treating url as differnt

I am using Disqus for comments management.But the problem is its treating below link as different
http://gpuzzles.com/mind-teasers/logical-age-riddle/
http://gpuzzles.com/mind-teasers/logical-age-riddle/?source=tracking1
as a result comments in one post is not reflecting in other post.
Please suggest a solution
By default Disqus will identify a unique thread by its unique URL in the window. This is a very easy way to integrate, but isn't too reliable as you're seeing.
To prevent this you would want to pass a 'disqus_identifier' and/or a 'disqus_url' javascript variable. You can read about these here: http://help.disqus.com/customer/portal/articles/472098
That'll override looking at the window location for a unique identifier.

Sitecore - rewrite " " to "-" in urls but still allow dashes as legal item names

I've read a half dozen guides on rewriting spaces to something more friendly in Sitecore, but all of them rely on Sitecore's <encodeNameReplacements/> element which also reverses the replacement requiring "-" to be an illegal character for names.
The problem with this is that the url of our application has a "-" in the hostname. Sitecore rewrites this resulting in a 404.
Does anyone have ideas on how to do this url rewriting in Sitecore without relying on <encodeNameReplacements and still allowing "-" as a legal item name character? Our current best idea is to use something slighty more complex than a plain "-" such as "--" or "_". This isn't a very good idea, so I'd appreciate any insight you guys have on the matter.
EDIT: We are running a multi-site setup with Sitecore 6.5
So, if I am assuming correctly, you want to replace spaces in item names with some other SEO-friendlier character. Whatever replacement you configure, you would need to apply the transformation on both sides of the equation (pun intended). So '--' or '_' will have to become illegal item name characters.
I generally think it's a bad idea to do this and would rather have my content editors determine the exact urls to their content.
But if you absolutely need to implement this as a rule, one of the solutions out there is to implement a custom handler to change your real item name while leaving the item display name in its original form.
Hope this helps.
Which version and build of Sitecore are you using?
I've just taken a look through Sitecore.Links.LinkProvider in Sitecore.Kernel and the BuildItemUrl method only replaces characters encodeNameReplacements on the path part of the URL so it should leave your hostname alone.
I would expect the same to happen to reverse, and looking at Sitecore.Pipelines.HttpRequest.SiteResolver the SiteContext is resolved by matching the requested Uri to the defined sites. Further down the process Sitecore.Pipelines.HttpRequest.ItemResolver decodes the Item Url but the Site has already been resolved at this stage.
I presume you have set the hostName attribute on the <site> elements? Having you tried setting the targetHostName attribute as well? Have you tried setting multiple hostNames, I don't expect it to work with spaces but worth a try if what you are saying is true:
<site name="website" hostName="my-site.com|my site.com" ... />
I tried replicating your issue on my local machine but it worked as expected for me... Unless you are working with very strange character sets then this is still the best way of encoding names in my opinion.

Changing CodeIgniter url_title from Czech characters to standard English characters

What's the best way to save CodeIgniter url_title's originally written using Czech characters as standard English characters? For example:
Currently this:
/projects/Hledám-sponzora-na-nákup-příslušenství-k-invalidní1/123
I'd prefer this:
/projects/hledam-sponzora-na-nakup-prislusenstvi-k-invalidni1/123
I tried changing just the url_title table collation to non-Czech, but it caused an error when submitting the form. Any ideas?
Just in case anybody needs it (a year later), try with convert_accented_characters() of the Text Helper. This is how I do it:
url_title(convert_accented_characters($title_with_accents), 'dash', TRUE)
Works quite well :)
You can also check the file application/config/foreign_chars.php and edit it if it's needed.
I don't understand what you are trying to do... Are these urls? If so, I'd choose numbers that associate to the titles you want to use.
Could you show the markup of the form? Also the controller function that handles the submission could be major help... Help us help you!

ASP MVC3 localizing URL query string parameters

I already know how to localize an ASP.NET MVC3 URL (using this technique).
This solution is very elegant and i already managed to tweak it to my needs.
But now i have this small (or rather huge) problem:
how is it possible to have localized url query parameters?
For example how is it possible to have this (US) english version
english URL: http://www.mysite.com/en-US/Classifieds/Search?ZipCode=92274
german (DE) version:
http://www.mysite.com/de-DE/Anzeigen/Suche?Postleitzahl=71710
spanish (ES) vesrion:
http://www.mysite.com/es-ES/Clasificados/Busqueda?Codigo_postal=08110
See the bolded part? This is what i'm looking for!
Thanks in advance
PS. I need this cause i think this will give much better SEO rankings. Is there anyone who can confirm this?
I can think of several ways of doing what you need. You may want to try to create your own HTML helper for localized links building. That could include the translation logic based on db table ( baseName, Culture, translation ). Once you've got this in place you either could refer to Request object and get the parameter by index, or create a logic to translate back ( again based on your table) to the base name.
Regarding your SEO question - I only know that MVC rewriting logic and 'friendliness' of the links is based on the fact that static-looking links are crawled faster then the dynamic ones. So that's something to consider on your site.( http://www.seo-consultant-services.co.uk/static-html-vs-dynamic-urls.html) I'm not an expert but I would guess that translating your url parameters makes sense if you expect users to search for services like this for example ' near ZipCode 92274' (I may be wrong)

opengraph - not reading my og-tags

I am looking for a solution for 3 days now, but cannot find it ...
I have this page with build in "send-button" to Facebook.
http://www.architectura.be/nieuwsdetail_new_fb_1.asp?id_tekst=2570
I have my og tags specified, but it is not working. (random image is showing, random title, ...)
Any help would be enormously apreciated !
Thanks
Andy is right. Let me put it another way; Facebook does not read all of the page that you specify (2570), it reads the og:url and then it looks for metadata at that address (2586); because that is meant to be the "canonical" or "reference" version of the page.
I don't know what you intend, so I can't tell you how to fix that.
But I will also point out that the HTML coding on your page is extremely bad and even when you get the URL sorted out, it's possible that Facebook will be unable to read the page correctly.
David
There is something wrong, so here is a list of possibilities:
locale: Do you really need to set a locale?.
type: Try to use the right type. Maybe use 'article' or something like that instead of using 'movie'.
url: The facebook crawler is checking the page with the url you set, 'http://...?id_tekst=2586'. When i look at the source code on that page, there are no opengraph parameters. You´re setting them on page 'http://...?id_tekst=2570'
image: Use an absolute path to your image, e.g. 'http://domain/image.jpg'
fb:admins: USER_ID has to be a valid userId or username (optional)
Hope that helps a little bit?

Resources