Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save Clients UTC Offset in Cookie to be Read by asp.net

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
US
Hi All
After many hours of trying to figure this out, I think I may have done it. I needed a way to save my clients UTCOffset to a cookie so I can adjust GMT time to their Local Time. This is how I accomplish it.

I have an htm page, called SetDefaults.htm, that has the following code
Code:
<html><head>
<script language="javascript">
	var rightNow = new Date();	
	document.cookie="clientTimeZoneOffset=" + rightNow.getTimezoneOffset()/60+"; path=/";
	location.reload();
</script>
</head><body></body></html>

This creates the cookie data i need to tell me how many hours off UTC the client is.

In my Global.asax page I have the following
Code:
protected void Session_Start(Object sender, EventArgs e)
{
     Server.Transfer("~/SetDefaults.htm");
}

Now I can read the cookie using
Code:
Request.Cookies[clientTimeZoneOffset].Value

Thats it.

RalphTrent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top