Is there a way to do your timezone offsets on the server side, by reading something in the request over http, instead of sending everything to the client and letting it deal with it?
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- Request.PathInfo issues and XSS attacks
- How to dynamically load partial view Via jquery aj
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- “Dynamic operations can only be performed in homog
- What is the best way to create a lock from a web a
- Add to htmlAttributes for custom ActionLink helper
We can get the time zone using the below code in server side instead of sending value from client.
Thanks...
Here's the solution I came up with, when I had the same issue with WCF web services:
How to get a WCF Web Service to return DateTimes in user's local timezone
Basically, I get my JavaScript/Angular code to determine the user's timezone, then pass this value to one of my WCF web services.
Notice how I have a web service called
getListOfRecords
which takes one parameter, the timezone-offset value.From there, my C# code reads in the database records, applies that timezone offset to the UTC
DateTime
values, and returns it to the client.In any of the events prior to Page Unload...Request.ServerVariables. If you want their physical timezone then you check their IP address and use an IP to Geo-Location conversion tool.
I'm not sure if there's another way you can do it, so if you require the timezone their computer is configured for, it would have to wait for the page load for a javascript...
Check detect_timezone.js - does a pretty good job determining the user's timezone
This is more complicated but I've had to resort to this scenario before because machine and user profile settings sometimes don't match your visitor's preferences. For example, a UK visitor accessing your site temporarily from an Australian server.
Use a geolocation service (e.g MaxMind.com) as suggested by @balabaster, to get the zone matching their IP (Global.Session_Start is best). This is a good match for local ISPs, but not so good for AOL. Store the offset from this in a session cookie.
Or use JavaScript to get the time zone offset as part of a form submission/redirect when the user enters the site. This is the browser's current offset, but not necessarily the visitor's preferred zone. Use this value as a default; store in another session cookie.
Allow the visitor to update the zone via a persistent cookie (for anonymous users) and a field in their account profile (if authenticated).
The persistent value #3 from overrides the session values. You can also store the same persistent cookie for authenticated users for displaying times before they login.