Question

I want to change the language in my website. I thought i could do it using a Handler, so the drop down would go for http://domain.com/Handler.ashx?language=en-US, f.i.

So, it calls the handler, that has this code:

string selectedLanguage = context.Request.QueryString["language"];

    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage);
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);

    context.Response.ContentType = "text/plain";
    context.Response.Write("Hello World");

    context.Response.Redirect(context.Request.UrlReferrer.AbsoluteUri.ToString());

But when it goes back, Thread.CurrentThread.CurrentCulture is set to pt-BR, which was the initial value.

My question is: the Thread on the Handler is different than the aspx page that loads the content? And what would you suggest as a work around?

Thank you

Was it helpful?

Solution

Response.Redirect() sends an HTTP redirect back to the user's browser, the browser then makes another request to the server. This results in IIS handling an entirely new request and, therefore, a new thread is created to handle this request.

Although I would not recommend a handler to accomplish this, if you switch to Server.Transfer, your idea MAY work, as Server.Transfer does not use Http Redirects but simply creates a new request to send through the ASP.NET pipeline, all within the context of the same initial request.

Hope that helps,

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top