Let me give you some background on my scenario. I got a multi language site and my cultures are stored in database and got a property that is public bool Active { get; set; }
-
If you come to my site with lets say a Russian culture on your browser, that is not supported on my site so i need to set the culture to “se” (or whatever).
-
If you come to my site with a supported culture but its not Active i need to set it to a default one “se” (or whatever).
Now I can do this check easy in my override IHttpHandler GetHttpHandler method. The thing is I dont want to make the call to the database everytime the site makes any call on the site. My thought is that I do a session[“firstVisit”] to reduce that check but I kinda don’t know how i should go about to that, because my scenario it say that
not set to an instance of an object on the session[“firstVisit”] line, so my question is how do I handle this? And what other options I got to go about this?
my thought is something like this
protected override IHttpHandler GetHttpHandler(System.Web.Routing.RequestContext requestContext)
{
String culture = requestContext.RouteData.Values["culture"].ToString();
if (HttpContext.Current.Session["firstVisit"].ToString() == string.Empty)
{
//do the check
}
var ci = new CultureInfo(culture);
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
return base.GetHttpHandler(requestContext);
}
EDIT
Doh why did I not think of that, I ended up just doing a check in the protected void Application_Start() to avoid sessions
Use global.asax.cs:
This method is called when the session is first created. You can do the check then, stuff your language info in the session and have it for as long as the session is live through the user’s interaction with your site.