0

buystuff.aspxというページを含む Web サイトがあります。buystuff.aspx.resxbuystuff.aspx.da-dk.resxという 2 つのローカル リソースを作成しました。

これは問題なく動作し、da-DK 設定でサイトに入るとそのバージョンが取得され、それ以外の設定で入るとデフォルトが取得されます。

ただし、私が望むのは、これをプログラムで設定することです。ユーザーが buystuff.aspx を入力すると、強制的に英語 (en-US) バージョンになり、buystuff.aspx?language=da と入力すると、強制的に da-dk バージョンになります。

次のコードではうまくいきません。

private void SetupLanguage()
{
    if (!string.IsNullOrEmpty(CurrentLanguage))
    {
        if (CurrentLanguage == "da")
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("da-DK");
            return;
        }
    }
    Culture = "en-US";
    UICulture = "en-US";
}

次のことも試しましたが、うまくいきませんでした。

private void SetupLanguage()
{
    if (!string.IsNullOrEmpty(CurrentLanguage))
    {
        if (CurrentLanguage == "da")
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("da-DK");
            return;
        }
    }
    CultureInfo info = CultureInfo.CreateSpecificCulture("en-US");
    Thread.CurrentThread.CurrentUICulture = info;
    Thread.CurrentThread.CurrentCulture = info;
}

デバッグ モードでは、コードが正常に実行されていることがわかります。ただし、buybtc.aspx を読み込むとき (そして、CurrentLanguage 変数は string.empty です)、buystuff.aspx.da-dk.resx からリソースを読み込みます。

何か案は?

4

1 に答える 1

0

わかりました、自分で解決しました(それらの時間はなくなりました-永遠に;))。

問題は web.config にあり、SEO の理由からいくつかのルールがありました。

 <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect domain.com to www" patternSyntax="Wildcard" stopProcessing="true">
          <match url="*"/>
          <conditions>
            <add input="{HTTP_HOST}" pattern="btcglobe.com"/>
          </conditions>
          <action type="Redirect" url="http://www.btcglobe.com/{R:0}"/>
        </rule>
        <!--To always remove trailing slash from the URL-->
        <rule name="Remove trailing slash" stopProcessing="true">
          <match url="(.*)/$"/>
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="{R:1}"/>
        </rule>
        <rule name="LowerCaseRule1" stopProcessing="true">
          <match url="[A-Z]" ignoreCase="false"/>
          <conditions>
            <add input="{URL}" matchType="Pattern" pattern="^.+\.((axd)|(js)|(xaml)|(asmx))$" ignoreCase="true" negate="true"/>
          </conditions>
          <action type="Redirect" url="{ToLower:{URL}}"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

また、web.config でカルチャを指定していたので、何をしても常に同じカルチャでした。

だから解決策:

  • web.config からグローバリゼーション情報を削除しました
  • 新しい CultureInfo("da-dk"); もすべて小文字であることを確認しました。

私のコードビハインドは次のようになりました:

private void SetupLanguage()
{
    if (!string.IsNullOrEmpty(CurrentLanguage))
    {
        if (CurrentLanguage == "da")
        {
            CultureInfo dkinfo = CultureInfo.CreateSpecificCulture("da-dk");
            CultureInfo.DefaultThreadCurrentCulture = dkinfo;
            CultureInfo.DefaultThreadCurrentUICulture = dkinfo;
            Thread.CurrentThread.CurrentCulture = dkinfo;
            Thread.CurrentThread.CurrentUICulture = dkinfo;

            return;
        }
    }
    CultureInfo info = CultureInfo.CreateSpecificCulture("en-us");
    CultureInfo.DefaultThreadCurrentCulture = info;
    CultureInfo.DefaultThreadCurrentUICulture = info;
    Thread.CurrentThread.CurrentCulture = info;
    Thread.CurrentThread.CurrentUICulture = info;

}
于 2013-04-28T13:06:30.370 に答える