Global.asax Application_BeginRequest fired after load events
Hi!
Building another website with umbraco, which features multilanguage. So I have a cookie and want to set the current thread's CurrentCulture with the selected culture inside this cookie.
I'm using the following code:
public class Global : umbraco.Global { protected void Application_BeginRequest(object sender, EventArgs e) { HttpCookie objCookie = Request.Cookies["culture"]; if (objCookie != null && !string.IsNullOrEmpty(objCookie.Value)) { try { CultureInfo objCulture = new CultureInfo(objCookie.Value); System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture = objCulture; } catch { } } } }
Inheriting from System.Web.HttpApplication doesn't change anything for me.
The problem is; when I put a breakpoint on the first line of code and on the OnInit/OnLoad/OnPrerender in some masterpage's codebehind, the loading breakpoint get's hit first, instead of the Application_BeginRequest begin called first... :-/
This is really odd behavior. It does work however, when using the ASP.NET development webserver (instead of IIS 7.5 (win 7) or IIS 7 (win server 2k8)). It does also work like expected, when switching the Pipeline mode to Classic, but that will break the UrlRewriteNet plug-in.
Well, I wanted to use the culture because of DateTime.Format() and the Dictionary Items. How should I set the proper culture within Umbraco then? (I have 3 ImageButtons (flags) to change the culture. These ImageButtons set a cookie with the correct culture.)
Can't you use assign host names (and corresponding culture) to achieve what you're after? You can assign a bogus domain name which you don't care about, but is required to be able to set the culture?
Well as far as I know the only way to have DateTime.Format() and the Dictionary Items output the correct language/locale is through the current culture. But if I'm wrong about that, I would be glad to hear!
As far as the DateTime.Format() concerns, I'm calling the Exslt.ExsltDatesAndTimes:formatdate() version from within XSLT. And this uses .NET to format the date, so .NET must be set to the users' current culture, right?
But Roel, what did you mean with setting the proper language within Umbraco? Is that possible through code-behind?
@kipusoep I'm not sure about setting the correct language through some api call (I have no experience with that) But I do no the proper language and culture is set if you use a certain hostname with a certain language within the Umbraco backoffice (on a particular start node) Or you could use ?lang=en in the querystring.
I was comparing the web.config of another website I made with the one I'm using for this website, because this problem did not occur with that website. Then I saw the following under system.webServer: <modules runAllManagedModulesForAllRequests="true">
I added this to the web.config and it worked! :D The reason I added this to the other website's web.config, is because of this:
Directory urls and authentication
if you use extensionless urls / directory urls with umbraco as well as authenticating users on your website, you need to add one additional setting to the web.config.
under <system.webserver> all umbaco's httpmodules are listed. Due to the way IIS process extensionless urls, you need to add: runAllManagedModulesForAllRequests="True" to the modules element, så it looks like this: <modules runAllManagedModulesForAllRequests="True">
That is all there is to it, copy over files, keep database connection, upgrade web.config file to a asp.net 3.5 compatible version, and you're done.
Global.asax Application_BeginRequest fired after load events
Hi!
Building another website with umbraco, which features multilanguage.
So I have a cookie and want to set the current thread's CurrentCulture with the selected culture inside this cookie.
I'm using the following code:
Inheriting from System.Web.HttpApplication doesn't change anything for me.
The problem is; when I put a breakpoint on the first line of code and on the OnInit/OnLoad/OnPrerender in some masterpage's codebehind, the loading breakpoint get's hit first, instead of the Application_BeginRequest begin called first... :-/
This is really odd behavior. It does work however, when using the ASP.NET development webserver (instead of IIS 7.5 (win 7) or IIS 7 (win server 2k8)). It does also work like expected, when switching the Pipeline mode to Classic, but that will break the UrlRewriteNet plug-in.
Does anyone know what's going on?
Not sure about the event order, but why do you need to set the culture like this? are you using this within your own custom code?
Because if you set the proper language within Umbraco also the proper culture will be set.
Well, I wanted to use the culture because of DateTime.Format() and the Dictionary Items. How should I set the proper culture within Umbraco then? (I have 3 ImageButtons (flags) to change the culture. These ImageButtons set a cookie with the correct culture.)
Can't you use assign host names (and corresponding culture) to achieve what you're after? You can assign a bogus domain name which you don't care about, but is required to be able to set the culture?
Cheers,
/Dirk
Well as far as I know the only way to have DateTime.Format() and the Dictionary Items output the correct language/locale is through the current culture. But if I'm wrong about that, I would be glad to hear!
As far as the DateTime.Format() concerns, I'm calling the Exslt.ExsltDatesAndTimes:formatdate() version from within XSLT. And this uses .NET to format the date, so .NET must be set to the users' current culture, right?
But Roel, what did you mean with setting the proper language within Umbraco? Is that possible through code-behind?
@kipusoep I'm not sure about setting the correct language through some api call (I have no experience with that) But I do no the proper language and culture is set if you use a certain hostname with a certain language within the Umbraco backoffice (on a particular start node) Or you could use ?lang=en in the querystring.
Still wanting this 'edit' button. Damn typos..
*know* instead of 'no'
w00t, I hasz fixed this!
I was comparing the web.config of another website I made with the one I'm using for this website, because this problem did not occur with that website.
Then I saw the following under system.webServer:
<modules runAllManagedModulesForAllRequests="true">
I added this to the web.config and it worked! :D
The reason I added this to the other website's web.config, is because of this:
Directory urls and authentication
if you use extensionless urls / directory urls with umbraco as well as authenticating users on your website, you need to add one additional setting to the web.config.
under <system.webserver> all umbaco's httpmodules are listed. Due to the way IIS process extensionless urls, you need to add: runAllManagedModulesForAllRequests="True" to the modules element, så it looks like this: <modules runAllManagedModulesForAllRequests="True">
That is all there is to it, copy over files, keep database connection, upgrade web.config file to a asp.net 3.5 compatible version, and you're done.
Found on: http://umbraco.org/blog
is working on a reply...