统一码和在 MVC URI 中使用国际 slug 名称?
我正在查看 MSFT Azure 上的 MVC 模式和实践指南他们的代码类似于以下内容:
public static string GenerateSlug(this string txt, int maxLength)
{
string str = RemoveAccent(txt).ToLower();
str = Regex.Replace(str, @"[^a-z0-9\s-]", string.Empty);
str = Regex.Replace(str, @"\s+", " ").Trim();
str = str.Substring(0, str.Length <= maxLength ? str.Length : maxLength).Trim();
str = Regex.Replace(str, @"\s", "-");
return str;
}
public static string RemoveAccent(this string txt)
{
byte[] bytes = System.Text.Encoding.GetEncoding("Cyrillic").GetBytes(txt);
return System.Text.Encoding.ASCII.GetString(bytes);
}
我必须做出哪些更改才能支持东方和非英语语言,并仍然保留 slug 的 SEO 优势?
I'm looking at the MSFT Patterns and Practices guide for MVC on Azure and they have code similar to the following:
public static string GenerateSlug(this string txt, int maxLength)
{
string str = RemoveAccent(txt).ToLower();
str = Regex.Replace(str, @"[^a-z0-9\s-]", string.Empty);
str = Regex.Replace(str, @"\s+", " ").Trim();
str = str.Substring(0, str.Length <= maxLength ? str.Length : maxLength).Trim();
str = Regex.Replace(str, @"\s", "-");
return str;
}
public static string RemoveAccent(this string txt)
{
byte[] bytes = System.Text.Encoding.GetEncoding("Cyrillic").GetBytes(txt);
return System.Text.Encoding.ASCII.GetString(bytes);
}
What changes will I have to make to support Eastern and non-english languages, and still keep the SEO benefit of the slug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以查看 如何在 StackOverflow 上生成 slugs。
You may take a look at how the slugs are generated on StackOverflow.