简体   繁体   中英

DateTime.TryParse failing in Azure Web App

My development machine's culture is en-NZ and my timezone is set to New Zealand time (UTC+12:00). A DateTime.TryParse is failing on the server, which is in West US.

  1. How can I check and change culture and time settings on my web app on the server?

  2. Can I run Powershell or C# code on the server interactively and see output, just to test stuff, like say

     Console.WriteLine(CultureInfo.CurrentCulture.ToString()); 

Any other thoughts are welcome if you think I'm approaching this the wrong way.

I just used Kudu to answer this. Kudu is amazing.

I just thought that "Kudu is the engine behind git deployments in Azure Web Sites. It can also run outside of Azure."

But go to https://[mysite].scm.azurewebsites.net/ . This is actually a web interface for Kudu and tells you everything you want to know about the environment. You can even run powershell and cmd. Check it out.

Fixed the problem by putting this in the web.config:

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

By the way, using powershell, the culture on the server was en-US (West US datacentre). The time was UTC. I didn't need to change the time, but here is how to do that:

https://blogs.msdn.microsoft.com/tomholl/2015/04/06/changing-the-server-time-zone-on-azure-web-apps/ .

Basically, "All you need to do is add an Application Setting (via the portal or the management APIs) called WEBSITE_TIME_ZONE and set that to the name of the time zone as defined in the Windows Registry under HKLM\\Software\\Microsoft\\Windows Nt\\CurrentVersion\\Time Zones\\ (for example, “AUS Eastern Standard Time”)."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM