问题
I have a project developed in ASP.NET webforms, the project has content in 2 different languages which can be selected from a dropdownlist, that project is available for download from the following link: http://www.mediafire.com/download/4d7dbdthh2094s6/test-idiomas-urls.rar I need that when I select any of the languages, the URL change from this: example.com/Default.aspx to this: example.com/en/home or example.com/es/home. I have excluded ASP.NET MVC. How could I make that work?
回答1:
Including Default.aspx
isn't friendly. That's a pain to type, and it's not good for SEO. You can use MapPageRoute to do your routing.
routes.MapPageRoute("","en", "~/English/Default.aspx");
routes.MapPageRoute("","sp", "~/Spanish/Default.aspx");
routes.MapPageRoute("","en/Contact", "~/English/Contact.aspx");
routes.MapPageRoute("","sp/Contact", "~/Spanish/Contact.aspx");
But I really hope you don't actually use different pages for each language? Probably better to use one page and then pass route values or use cookies for getting/setting the language.
来源:https://stackoverflow.com/questions/29679999/add-friendly-urls-to-multi-lingual-asp-net-website-without-using-mvc