Answered by:
Correct method to share code to retrieve information

Question
-
User1883908716 posted
Hi all,
I'm trying to build a multilanguage app with webmatrix. Basically the app will have a default language (eg. 'IT') and the other languages will be selected manually by the user from a link in the menu. Instead of a request, as per mikesdotnetting template code, I would like to extract and filter the content from a database using a "UrlData[0]" string (es. IT,ES,EN,...) avoiding the request into the Url. But I don't know how.
Using the "_StartPage.cshtml" by href I can get a result but not the same that I can have with the post method and it's not that I would like to have because the URL include the request string eg. "?lang=en"
<a href="~/?lang=iT-it">IT</a> <a href="~/?lang=en-en">EN</a> <a href="~/?lang=fr-FR">FR</a> <a href="~/?lang=de-DE">DE</a>
The Url that I would like to have is in eg.:http://localhost:54083/ --> Value IT or it-IT
http://localhost:54083/IT/ --> Value IT or it-IT
http://localhost:54083/EN/ --> Value EN or en-GB
...
I tried with Functions* but 1) i don't know if it the correct method, 2) I don't know in deep "how to". here below the last don't working code.
public string UserLang (string Url) { var fmylang = ""; try { fmylang = Url; return fmylang; } catch (WebException ex) { fmylang="IT"; return fmylang; } }
Can someone help me to find a correct code to check UrlData and manage the information.
Thanks in advance,
Nik
*: To improve myself, where I can found clear and detailed information about functions? eg. when use it, public static..., how call function etc.etc.
Sunday, April 19, 2015 8:34 PM
Answers
-
User1883908716 posted
Solved using _PageStart:
@using System.Web.Mvc; @using System.Text; @using System.Globalization; @{ var MyLang =""; Layout = "~/_SiteLayout.cshtml"; if(UrlData[0].ToString() =="") { PageData["myLang"]= "it-IT"; PageData["myLangHtml"] ="it"; Culture = UICulture = "it-IT"; } else { var db_lang = Database.Open("StarterSite"); var flang = UrlData[0]; var SQLSELECT = "SELECT * FROM SYS_LANG where LANG=@0"; var Details = db_lang.QuerySingle(SQLSELECT, flang); int lCount = 0; foreach(var Detail in db_lang.Query(SQLSELECT, flang)) { lCount = lCount + 1; } if (lCount > 0) { PageData["myLang"] = Details.CULTURE_CODE; PageData["myLangHtml"] = Details.LANG; Culture = UICulture = Details.Culture_Code; } else { PageData["myLang"]= "it-IT"; PageData["myLangHtml"] ="it"; Culture = UICulture = "it-IT"; } } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, April 26, 2015 2:24 AM
All replies
-
User1853794821 posted
public string UserLang (string Url) { var fmylang = ""; try { fmylang = UrlData[0]; return fmylang; } catch (WebException ex) { fmylang="IT"; return fmylang; } }
Monday, April 20, 2015 9:26 AM -
User1883908716 posted
Hi
already used urldata [0]
... it don't workMonday, April 20, 2015 11:21 AM -
User1883908716 posted
Solved using _PageStart:
@using System.Web.Mvc; @using System.Text; @using System.Globalization; @{ var MyLang =""; Layout = "~/_SiteLayout.cshtml"; if(UrlData[0].ToString() =="") { PageData["myLang"]= "it-IT"; PageData["myLangHtml"] ="it"; Culture = UICulture = "it-IT"; } else { var db_lang = Database.Open("StarterSite"); var flang = UrlData[0]; var SQLSELECT = "SELECT * FROM SYS_LANG where LANG=@0"; var Details = db_lang.QuerySingle(SQLSELECT, flang); int lCount = 0; foreach(var Detail in db_lang.Query(SQLSELECT, flang)) { lCount = lCount + 1; } if (lCount > 0) { PageData["myLang"] = Details.CULTURE_CODE; PageData["myLangHtml"] = Details.LANG; Culture = UICulture = Details.Culture_Code; } else { PageData["myLang"]= "it-IT"; PageData["myLangHtml"] ="it"; Culture = UICulture = "it-IT"; } } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, April 26, 2015 2:24 AM