开发者

Sanitizing non-English letters to use safely in URLs

What is the best way, in .NET, to create safe URLs from titles of posts? For example, I may have a post "test wıth non enğlİşh çharaçters" and I want to turn this into a URL safe form while still maintaining the readability purpose of the title being URL, such as, "test-with-non-english-character开发者_如何转开发s", and I will use them as http://mysite/blog/5/test-with-non-english-characters I can just iterate over the string characters and either leave ALL letters as they are (not safe to use in URLs), or wipe out all non-English characters and turn them into an underscore etc. (breaks the purpose of readability, as posts will/may be in non English languages). I'm sure that there's a method for converting ş to s and Ğ to G etc. just like in an accent insensitive search query in SQL server.


See my answer to another question to remove accents from a string.

Note that this doesn't completely solve the problem. For example, Asian ideograms or non latin letters will not be transliterated to english (latin) letters using this code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜