there is a method called "ExtractLanguageName(string localPath)" in WebUtil, which is suppoed to extract the language from the request url (I think).

But what value for "localPath" does this method expect?

If the request url is something like "http://mysite/fr-ca?search=true" then the Request I get has values:
FilePath = "/"
RawUrl = "/fr-ca?search=true"

(To tell the truth I don't understand why FilePath isn't "/fr-ca" ?)

Neither of those strings results in a "correct" return value from ExtractLanguageName.

Is something else going on? Why is FilePath simply "/".

Thanks for any advice.


ExtractLanguageName will do this:

if (string.IsNullOrEmpty(localPath) || !localPath.StartsWith("/", StringComparison.InvariantCulture))
   return (string) null;
int num = localPath.IndexOfAny(new char[2]{ '/', '.' }, 1);
if (num < 0)
    num = localPath.Length;
return localPath.Substring(1, num - 1);

So you need a value that includes your full path - but not the querystring.

| improve this answer | |
  • Yes thanks. I am beginning to suspect that something else is going on in my application before it reaches the point where I want to extract the language from the url. I do not understand why my FilePath is "/" instead of "/fr-ca" (or "/fr-ca/"). Obviously I can't use the FilePath or the RawUrl which I have available, so I'll probably just write my own language-extraction method specific to my circumstances. In fact, just adding a "?" to the IndexOfAny call, and using the RawUrl, will work for me. – xdzgor Nov 2 '19 at 10:27
  • 3
    The StripLanguageProcessor in the pipeline will remove /fr-ca from the url. – Mark Cassidy Nov 2 '19 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.