Users can have a Cookie called lang
that contains either the value "default=1" (English) or "default=2" (French). This cookie is used to determine their preferred language. I have a function that needs to take the cookie and return the language has an Enum. If the cookie doesn't exist, I want to return English. I cannot change the cookie value.
Language enum:
Public Enum Language Undefined = 0 English = 1 French = 2 End Enum
Function:
Public Function GetLangFromCookie() As Language If HttpContext.Current.Request.Cookies.Get("lang") IsNot Nothing Then Dim langCookie = HttpContext.Current.Request.Cookies.Get("lang").Value Return If(langCookie(langCookie.Length - 1) = "1", Language.English, Language.French) End If Return Language.English End Function
I feel like this is not efficient and not secure but I don't know how to improve it. Any suggestions?