1

Resolved

Wrong BrowserBestMatch implementation

description

When I try to request a page for the first time (without any culture specified in url or cookie), the BrowserBestMatch function does not return the expected culture.

My browser (Google Chrome) primarily expects French (fr-FR) but i get the application default culture instead (en-GB).

This happens because in the following code we expect to get a string array from the "Accept-Language" field of the request header with each string representing one and only one language:
string[] acceptLanguageHeader = null;
            if (context.Request.Headers.TryGetValue("Accept-Language", out acceptLanguageHeader) && acceptLanguageHeader != null)
            {
This is not the case. For me, the acceptLanguageHeader variable will contain the following string (There is only one string in the array...):

fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4

This is normal behaviour according to the specification:
Accept-Language HTTP header specification

The string needs to be split with the comma character before being passed to the parseLanguage method because this is what this method expects.

To fix this, you should replace the flowing code:
foreach (var language in parseLanguages(acceptLanguageHeader))
with this code:
foreach (var language in parseLanguages(acceptLanguageHeader[0].Split(',')))

comments

frankabbruzzese wrote Jul 7 at 8:43 PM

We can't apply your fixe since the bug is in the Katana basic module that should extract the various languages and put each of them into a different element of the array. The application of your fix might break the code when this bug will be fixed. We will fix by verifying if the languages have been parsed properly by Katana and if not, we will build properly the array.

frankabbruzzese wrote Jul 7 at 9:58 PM

Please download the new fixed sources, to see if the issue disappears. As soon as you confirm your issues has been solved we'll publish binaries, on both Codeplex and Nuget.

Asshiah wrote Jul 8 at 10:07 AM

This is fixed.

Thank you.

frankabbruzzese wrote Jul 11 at 7:33 AM

if you like this owin module, please spend some minute to review and rate it.