Azure中的货币设置



我有一个小的ASP.NET MVC网站,可以显示员工的工资详细信息。

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

在我的本地机器上,它显示罚款,例如66000英镑,但当上传到Azure时,它显示的是一美元,例如660000美元。

在成立时,我选择了西欧作为我的地点,但我显然需要做一些其他的事情来展示。有什么想法吗?

您需要在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");

此问题与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)
}

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

我的解决方案是修改默认用户NTUSER.DAT文件,这是所有未来用户创建的模板。使用这个特定的工作者角色,该文件存储在D:UsersDefault UserNTUSER.DAT中,尽管我们的物理服务器将其定位在C.中

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

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

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

[CmdletBinding(SupportsShouldProcess=$True)]
Param(
[string]
$NTUserDatPath = "D:UsersDefault UserNTUSER.DAT"
)
If(!(Test-Path $NTUserDatPath)){
" Write-Error $NTUserDatPath incorrect"
}
REG load HKLMTempHive $NTUserDatPath
$Default = "HKLM:TempHiveControl PanelInternational"
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 HKLMTempHive 

这是实时GitHub版本

最新更新