Azure中的货币设置

时间:2012-12-13 10:43:52

标签: azure

我有一个小的ASP.NET MVC站点,显示员工的薪资详情。

<td align="right">@String.Format("{0:c}", Model.Salary)</td>

在我的本地计算机上显示正常£66,000,但是当上传到Azure时,它显示的是一美元,例如$ 66,000名。

在设置时,我选择了西欧作为我的位置,但我显然需要做一些其他事情才能以英镑显示。有什么想法吗?

3 个答案:

答案 0 :(得分:19)

您需要在web.config中的应用程序级别设置特定文化,如下所示

<configuration>
    <system.web>
        <globalization uiCulture="en-GB" culture="en-GB" />
    </system.web>
</configuration>

或者你也可以在global.asax文件中设置下面的 Application_PreRequestHandlerExecute()

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");

答案 1 :(得分:2)

此问题与Windows Azure无关,但它仅归结为本地化(您计算机上的默认文化可能与Windows Azure中的默认文化不同)。尝试将文化更改为en-GB:

public ActionResult DoSomething()
{
    System.Threading.Thread.CurrentThread.CurrentCulture
        = new System.Globalization.CultureInfo("en-GB");
    System.Threading.Thread.CurrentThread.CurrentUICulture
         = new System.Globalization.CultureInfo("en-GB");

    ...
    model.Salary = 66.000;
    return View(model)
}

答案 2 :(得分:1)

我遇到了尝试在Azure中使用Microsoft HPC Server 2012辅助角色的问题。我需要将提交工作的每个用户设置为en-GB而不是en-US,这主要是由于客户端应用程序中的日期格式问题。

我的解决方案是修改默认用户NTUSER.DAT文件,该文件是所有未来用户的模板。使用此特定辅助角色,该文件存储在D:\Users\Default User\NTUSER.DAT中,尽管我们的物理服务器将其放在C中。

除非您转到文件夹选项并取消选中隐藏受保护的操作系统文件并选中显示隐藏文件,否则您无法在Windows资源管理器中看到该文件。

然后,您可以对用户注册表项进行任何更改,然后创建配置文件的下一个用户将继承这些设置。由于Azure启动脚本在创建任何本地用户之前运行,因此您可以强制所有新用户继承这些默认值。

这是一个PowerShell脚本,可确保Azure辅助角色使用en-GB而不是en-US

[CmdletBinding(SupportsShouldProcess=$True)]
Param(
  [string]
  $NTUserDatPath = "D:\Users\Default User\NTUSER.DAT"
  )

If(!(Test-Path $NTUserDatPath)){
   " Write-Error $NTUserDatPath incorrect"
}

REG load HKLM\TempHive $NTUserDatPath

$Default = "HKLM:\TempHive\Control Panel\International"

Set-ItemProperty -Path $Default -Name "iCountry" -Value "44" -Force
Set-ItemProperty -Path $Default -Name "Locale" -Value "00000809" -Force
Set-ItemProperty -Path $Default -Name "LocaleName" -Value "en-GB" -Force
Set-ItemProperty -Path $Default -Name "sCountry" -Value "United Kingdom" -Force
Set-ItemProperty -Path $Default -Name "sCurrency" -Value "£" -Force
Set-ItemProperty -Path $Default -Name "sLanguage" -Value "ENG" -Force
Set-ItemProperty -Path $Default -Name "sLongDate" -Value "dd MMMM yyyy" -Force
Set-ItemProperty -Path $Default -Name "sShortDate" -Value "dd/MM/yyyy" -Force
Set-ItemProperty -Path $Default -Name "sTimeFormat" -Value "HH:mm:ss" -Force
Set-ItemProperty -Path $Default -Name "sShortTime" -Value "HH:mm" -Force
Set-ItemProperty -Path $Default -Name "iDate" -Value "1" -Force
Set-ItemProperty -Path $Default -Name "iFirstDayOfWeek" -Value "0" -Force 
Set-ItemProperty -Path $Default -Name "iFirstWeekOfYear" -Value "2" -Force
Set-ItemProperty -Path $Default -Name "iMeasure" -Value "0" -Force
Set-ItemProperty -Path $Default -Name "iNegCurr" -Value "1" -Force
Set-ItemProperty -Path $Default -Name "iPaperSize" -Value "9" -Force
Set-ItemProperty -Path $Default -Name "iTime" -Value "1" -Force
Set-ItemProperty -Path $Default -Name "iTLZero" -Value "1" -Force

REG unload HKLM\TempHive 

Here is the live GitHub version