Umbraco Content Name - umbraco

In Umbraco CMS, I would like to prevent the contents to have names having invalid URL character such %, > and etc.
How should I do that?
Regards,
Nami

Have a look at your /config/umbracoSettings.config file, it already has a set of replace characters, among which the % character. You can add more if you want to.
If, for any reason you would want to completely prevent those characters in the nodename, you would have to write an afterSave eventhandler so you can do the replace in your own custom code.

Related

How to link to internal link with ampersand?

I am trying to make an internal link to a heading called "word & word".
Since I am using Jekyll, the content is in Markdown files and the heading I want to link to looks like this:
### word & word
I know that I can not use & in URLs.
Therefore this would not be an option:
#word-&-word
I also tried:
#word-%26-word
and
#word-&-word
#word-%26amp;-word
#word-%20amp%3B-word
However, both versions are not working.
What would be the appropriat way to fix this?
Kramdown is striping non alphanumeric from header id's and replacing spaces by -.
You can just check this behavior with :
- mandatory
{:toc}
### word & word
Resulting link in generated table of content is #word--word
See kramdown documentation

Change Encoding in ModelState.ModelError

Here is my problem: I add a message to ModelError with addModelError(String.Empty,”My message”).
In my view I just call #Html.ValidationSummary().
The message is in German and the characters Ö, Ä, Ü are just shown as questionmark. How do I change that?
As I see it there are two options. One option is to write a custom validation summary helper which doesn't HTML encode the messages like described in the link that Kartikeya Khosla provided. Or, and that’s what I did, Just use the Unicode reference in the message string. The solution in Kartikeya is more elegant, but in my case it is a lot of code to change two characters. By the way here a link to look them up if anybody wants to do the same:
http://www.utf8-chartable.de/unicode-utf8-table.pl?utf8=oct&unicodeinhtml=dec&htmlent=1

How to differentiate a link from text?

I have lines of text and I have to find whether these lines contain some link . how can I do it?Firstly I thought of finding www in the text but some links might not have www . Secondly I thought of finding http in text but again all links do not contain http. what to do?
Here is a regexp adapted from http://mathiasbynens.be/demo/url-regex entry by #diegoperini (Ruby syntax; you might need to change some details like Unicode \uXXXX to whatever your system uses):
(?:(?:https?|ftp):\/\/)?(?:\S+(?::\S*)?#)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?

ASP.NET MVC Colon in URL

I've seen that IIS has a problem with letting colons into URLs. I also saw the suggestions others offered here.
With the site I'm working on, I want to be able to pass titles of movies, books, etc., into my URL, colon included, like this:
mysite.com/Movie/Bob:The Return
This would be consumed by my MovieController, for example, as a string and used further down the line.
I realize that a colon is not ideal. Does anyone have any other suggestions? As poor as it currently is, I'm doing a find-and-replace from all colons (:) to another character, then a backwards replace when I want to consume it on the Controller end.
I resolved this issue by adding this to my web.config:
<httpRuntime requestPathInvalidCharacters=""/>
This must be within the system.web section.
The default is:
<httpRuntime requestPathInvalidCharacters="<,>,*,%,&,:,\,?"/>
So to only make an exception for the colon it would become
<httpRuntime requestPathInvalidCharacters="<,>,*,%,&,\,?"/>
Read more at: http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.requestpathinvalidcharacters.aspx
For what I understand the colon character is acceptable as an unencoded character in an URL. I don't know why they added it to the default of the requestPathInvalidCharacters.
Consider URL encoding and decoding your movie titles.
You'd end up with foo.com/bar/Bob%58The%20Return
As an alternative, consider leveraging an HTML helper to remove URL unfriendly characters in URLs (method is URLFriendly()). The SEO benefits between a colon and a placeholder (e.g. a dash) would likely be negligable.
One of the biggest worries with your approach is that the movie name isn't always going to be unique (e.g. "The Italian Job"). Also what about other ilegal characters (e.g. brackets etc).
It might be a good idea to use an id number in the url to locate the movie in your database. You could still include a url friendly copy of movie name in your url, but you wouldn't need to worry about getting back to the original title with all the illegal characters in it.
A good example is the url to this page. You can see that removing the title of the page still works:
ASP.NET MVC Colon in URL
ASP.NET MVC Colon in URL
Colon is a reserved and invalid character in an URI according to the RFC 3986. So don't do something that violates the specification. You need to either URL encode it or use another character. And here's a nice blog post you might take a look at.
The simplest way is to use System.Web.HttpUtility.UrlEncode() when building the url
and System.Web.HttpUtility.UrlDecode when interpreting the results coming back. You would also have problems with the space character if you don't encode the value first.

ASP.Net MVC FileStreamResult, valid chars for FileDownloadName

I have an action method that returns a FileStreamResult, the download works fine, the problem is that although I set the FileDownloadName property of the result object, some of the files are downloaded with another name (specifically the last part of the address of the page I'm working on. e.g. in the page "http://localhost:5479/Items/Edit/277" it will download a file called "277").
This happens when the name of the file contains special chars (e.g. "San José.jpg"), but it works just fine when the name doesn't have such chars (e.g. "San Jose.jpg").
So, my question is, how do I allow the user to download a file with special chars in its name? or, if it isn't possible, is there a method that removes all the special chars from a string or do I have to create one?
Thanks
Actually I just found a way to fix this.
Basically what I have to do is use the HttpUtility.UrlEncode method to convert the name of the file, when the file is downloaded it will get almost the same name as the original file (the difference being the spaces replaced with a plus (+) sign).
Hope this helps someone else.
I have the same Problem. A better solution is HttpUtility.UrlPathEncode(...) since it doesn't replace space by '+'.

Resources