Question Globalisation-Cookie problem?

raysefo

Well-known member
Joined
Jul 21, 2010
Messages
207
Programming Experience
Beginner
Hi,

I found an article about globalisation (multi language support)when i googled. It was working fine. But the deal is, if client does NOT accept cookies, what should i do? I mean is there another way to do it without cookie? I tried to use Sessions but global.asax Begin Application does NOT like Sessions. Any help would be great.

thanks in advance
 
You mean this http://www.vbdotnetforums.com/web-forms/43968-globalization-question.html ?
raysefo said:
Dim cookie As HttpCookie = New HttpCookie("culture")
cookie.Value = ddlLanguage.SelectedValue
Response.Cookies.Add(Cookie)
Without cookies enabled you have to find other storage, ASP.NET State Management Overview
You can for example store the value in Session object,
VB.NET:
Session("culture") = ddlLanguage.SelectedValue
To enable session when there is no cookies you also have to add this element to web.config file in system.web section:
HTML:
<sessionState cookieless="AutoDetect" />
ASP.Net will then store the session id in request url when cookies are disabled.
 
You can certainly deal with sessions from within global.asax ... just you have to access the session object from the Context e.g.

VB.NET:
    Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs)
        HttpContext.Current.Session("YourSessionName").ToString()
    End Sub
 
kulrom,

I tried to use session in my Application_BeginRequest like below but i m getting " System.NullReferenceException: Object reference not set to an instance of an object."

If Not HttpContext.Current.Session("lang") Is Nothing Then

Dim ci As New System.Globalization.CultureInfo(HttpContext.Current.Session("lang").ToString())
System.Threading.Thread.CurrentThread.CurrentCulture = ci
System.Threading.Thread.CurrentThread.CurrentUICulture = ci
Else
Dim ci As New System.Globalization.CultureInfo("tr-TR")
System.Threading.Thread.CurrentThread.CurrentCulture = ci
System.Threading.Thread.CurrentThread.CurrentUICulture = ci

End If
 
I initialize it in Session_start like below;

Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
Session("lang") = Thread.CurrentThread.CurrentCulture.ToString
 
Back
Top