开发者

Retrieve Client Time with ASP.NET

开发者 https://www.devze.com 2022-12-14 03:43 出处:网络
Is it possible to request the time on a client co开发者_如何学Cmputer with ASP.NET without using javascript?i don\'t believe so. javascript executes on the client and therefore has access to the clien

Is it possible to request the time on a client co开发者_如何学Cmputer with ASP.NET without using javascript?


i don't believe so. javascript executes on the client and therefore has access to the client attributes. asp.net code behind files are procesed on the server and therefore do not have access to client data.


Agree with jmatthews.

What I do is on login to the system, I have javascript to write the client time to a hidden field, then when the page posts I use that to compute an offset vs the server time. Anytime in the application I need the client time I can just apply the offset to the current server time. Saves having to "ask" for it at a random point, if that helps.


The only information about the client that the server can see without JavaScript is what comes over the wire in the HTTP headers. Unfortunately, that doesn't include the current time.

About the closest you can get without script is to measure approximate elapsed time, with coarse granularity. You could do that by setting a cookie with a short expiration time, and then looking to see if the cookie has expired, in which case it will no longer be sent to the server.

Another trick for elapsed time would be to set a short cache expiration time on an object on the page; the object will only be requested again once the cache entry expires.

You can also estimate the current local time at the client by using a GeoIP database to find the country and therefore the time zone.

0

精彩评论

暂无评论...
验证码 换一张
取 消