473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Store flag in cache/session on BeginRequest event

Hello,
On BeginRequest event I check and set user language settings. First I
check for browser's accepted languages and set Cultureinfo. If
browserlanguage is not supported, CultureInfo is set to a predefined
defaultvalue (en-US).
However, a visitor must be able to manualy change the language
settings. This is done by querystring-parameter.

Above works great, but whenever the next page is loaded, CultureInfo is
reset to browserlanguage. I can't find a way to store a bool value,
indicating browserlanguage/default language has been set before. I
tried the Runtime Cache, but this doesn't seem to be persistant.

TIA

###

This is what my code looks like ...

private void context_BeginRequest(object sender, EventArgs e)
{

HttpRequest request = ((HttpApplication)sender).Request;

// browser language
if (request.ServerVariables["HTTP_ACCEPT_LANGUAGE"] != null)
{
_httpAcceptLanguage =
request.ServerVariables["HTTP_ACCEPT_LANGUAGE"];
}

// check for manual language-switch
NameValueCollection queryString = request.QueryString;
LoadCulture(ref queryString);

}

private void LoadCulture(ref NameValueCollection qstring)
{
if (qstring != null && qstring["lan"] != null)
{
try
{
Thread.CurrentThread.CurrentCulture = new
CultureInfo(qstring["lan"].Trim());
}
catch
{
this.LoadDefaultCulture();
}
finally
{
setCulture();
}
}
else if ( HttpRuntime.Cache["BrowserLanguageIsSet"] == null )
{
// if no language is set, try to set browser language
// unsupported browserlanguage will load default
if (_httpAcceptLanguage != string.Empty)
{
setBrowserLanguage();
}
else
{
this.LoadDefaultCulture();
}
HttpRuntime.Cache.Insert("BrowserLanguageIsSet", true, null);
setCulture();
}
}

Nov 17 '05 #1
0 2019

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Joakim Westman \(Elicit AB\) | last post by:
Hi! I have a page that generates a lot of HTML, and I am considering different solutions to constrain the amount of code that is sent back to the client. One thing I thought about is the...
2
by: NWx | last post by:
Hi, Is Cache appropriate to store persistent variables used across the application? What I want is to store UserID for currently logged user, SessionID (my own SessionID, which keep track of...
0
by: Michael O'Brien | last post by:
I'm trying to hook in a specialized state store server into ASP.NET. I understand I can create a HttpModule and hook the events OnAcquireState and OnReleaseState. So far so good. But, it seems...
18
by: Rippo | last post by:
Hi I am using role base forms authentication in asp.net and have come across a problem that I would like advice on. On a successful login a session variable is set to identify a user. This is...
7
by: Shadow Lynx | last post by:
I realize that his question has been asked, in many other forms, many times in this group. Even so, my tired eyes have not yet found a sufficient answer, so I've decided to "reask" it even though...
8
by: graphicsxp | last post by:
Hi, I'm trying to figure out the best way to redirect the user to a special page when in my code i'm trying to use a Session object and that one is nothing. Oviously I could do: if...
11
by: john_c | last post by:
I'd like to store information for roles in Session variables. RoleA has a specific set of values, RoleB has a specific set and so one. When I access values for RoleA, it looks like this: ...
2
by: Sobin Thomas | last post by:
Hi All....... I am a beginner in asp.net.I need your help.I have a gridview control in my Default.aspx page.I use data adapter to fill a datatable and then I set the datasource of the gridview as...
5
by: =?Utf-8?B?Y2hlY2tyYWlzZXJAY29tbXVuaXR5Lm5vc3BhbQ== | last post by:
I have a site which I secure with forms authentication. When the user's sign on and hit one of the secure pages, I have this line in my code to ensure that the browser does not cache the page;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.