I try to save a List in a Session by converting it into a Byte[]. But when i try to Convert it back to a List i only get some random Numbers. This is the only way i can save the list with the languages in it.
Below the Code where i convert and save it in the session
private void AllowedLanguages(Userdata User)
{
List<string> languages = new List<string>();
if (User.Deutsch == true) { languages.Add("Deutsch"); }
if (User.Englisch == true) { languages.Add("Englisch"); }
if (User.Franz?sisch == true) { languages.Add("Franz?sisch"); }
if (User.Italienisch == true) { languages.Add("Italienisch"); }
if (User.Japanisch == true) { languages.Add("Japanisch"); }
if (User.Mandarin == true) { languages.Add("Mandarin"); }
if (User.Polnisch == true) { languages.Add("Polnisch"); }
if (User.Portugiesisch == true) { languages.Add("Portugiesisch"); }
if (User.Spanisch == true) { languages.Add("Spanisch"); }
byte[] LanguagesInBytes = languages
.SelectMany(s => System.Text.Encoding.ASCII.GetBytes(s))
.ToArray();
HttpContext.Session.Set("AllowedLanguages", LanguagesInBytes);
}
Here is the Code where i try to get it back into an Arraylist or any other type of list with strings is possible
var LanguagesByte = HttpContext.Session.Get("AllowedLanguages");
for (int i = 0; i < LanguagesByte.Length; i++)
{
String str = new String(LanguagesByte[i].ToString());
Languages.Add(str);
}
The List should look like before after i convert it back to display it on a page. Is this even the right way to do it or am i completly wrong?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…