Getting the client UTC Offset with ASP.NET

21 09 2007

I have a database where date and time are stored in GMT/UTC to have a uniform time zone reference.  The problem is that it isn’t very user friendly to display the GMT/UTC values.  In addition, we wanted to get the offset without having the user log in and get preference settings.

 Our approach was to get the client offset with JavaScript and added a function that is fired when the page is loaded.


<script>
function GetClientUtcOffset()
{
    var d = new Date();
    document.forms[0]["UtcOffset"].value
        = d.getTimezoneOffset();
}
</script>

Note that the method getTimezoneOffset() returns the unit value in minutes.  Within the body of the page we call the function during the onload event of the body and used a hidden field for the UTC Offset value that we’ll be getting that we’ll be accessing in our code behind.

<body onload="GetClientUtcOffset();">
  <form id="form1" runat="server">
      <input type="hidden" runat="server" id="UtcOffset" />
  .
  .
  .

In our code behind, we got the value and put it in a cookie. The alternative was to put it in a session.


protected void Page_Load(object sender, EventArgs e)
{
  if (IsPostBack && Request.Cookies["utcOffset"] == null)
  {
      HttpCookie utcOffsetCookie =
        new HttpCookie("utcOffset", "0");
      if (!string.IsNullOrEmpty(UtcOffset.Value))
          utcOffsetCookie.Value = UtcOffset.Value;
      Response.Cookies.Add(utcOffsetCookie);
  }
}

At this point, you can retrieve the cookie from any other page and adjust your time values accordingly. Only caveat to this is that the client must hit the page first and then send a post back to get the value of their offset. In our case, we added the code on our login page since we didn’t allow annonymous access to the site.

Read the rest of this entry »





Road to Wellville

20 09 2007

No I’m not referring to the movie.  Mid-August (2007), I decided to quit smoking.  Well, in all honesty, I was hacking and coughing at the time and had to stop to get well.  After recovering from my coughing bouts, I decided to quit all together.  I needed some other motivation to keep me on the wagon, so to speak.  To help reinforce being smoke free, I went ahead and joined a gym (24 Hour Fitness) - everytime I’m breathing hard due to exertion I’m reminded why I stopped smoking.

I started going to the gym around the last week of August and thus far have been able to keep my work out schedule.  I go 5-6 days a week where I alternate between weight training and cardio workouts.  On my cardio days, I’ll usually do 30 min. on the eliptical machine and another 30 min. on the tread climber.  I’ve got bad knees and these two machines seem to be the most forgiving on that body part.

My goal is to get down to about 200 lbs., I was at 251 lbs. on the first day with my trainer.  I do need to get a scale and tape measure to monitor my weekly progress.  Maybe I’ll write a ‘lil app to track and display the data points that I can i-frame onto here.





Hello World – MSAT 3.0

20 09 2007

Traditionally, the “Hello World” program/script is the first few lines of code that a new developer writes.  Similarly, the Microsoft Security Assessment Tool (MSAT) version 3.0 is my first published application available to the public (MSAT installer).

As imposing as the name may sound, specially with the word “Security” in there, it really is a simple application.  It isn’t a pervasive application that would examine your systems and network.  Instead, think of it as a long (and I mean long) questionaire that covers anywhere from anti-virus use to policies and procedures regarding employee termination/exits.  Based on the user’s answers, a score is generated and can be compared to other companies/organizations.  Your organization’s health security report can be viewed as a graphical representation with recommendations on how you can improve security.

I inherited the application back in April 2007 when it was in its 2.0 version.  For 3.0 the following features and modifications were made.

  • Added additional questions to the base assessment questionaire.
    • Re-visit, re-factor and re-normalized scoring mechanism.
  • Disable globalization/localization
  • Update references and recommendations
  • Encrypt serialized XML files (both data source and data outputs)

Version 3.0 doesn’t seem like much but it ended up quite the little beast.  Unfortunately I inherited an application that didn’t follow the best coding practices and there were significant portions that essentially had to be re-written.  There were times where I wanted to submit code snippets to Daily WTF.

Eventually I was able to get the application up to par to be released in time for this year’s TechEd.  I’ve continued working on the application since and version 3.5 is in its evaluation stages at this time.  I’ll add another blog about 3.5 and provide the feature/change set.





Vehicle Version Upgrade

14 09 2007

After being car-payment free for the last couple of years, I finally broke down and traded in my old vehicle, a 2000 Mustang.  Pretty much the basic model – manual transmission, cloth seats and all standard equipment.

2000 Ford Mustang

This was taken around February 2007 while I was in Utah.  High torque, rear wheel drive vehicle aren’t that great in the snow.  While in Utah, I did a 540 degree spin across a 4 lane highway while it was snowing.  I’ll save the details on that for another blog.

 Anyway, last Labor Day weekend, I went and purchased an Altima.  Actually quite a bit of a jump in terms of amenities available when compared to my former car.  I think with the exception of satellite radio, a sunroof wind shield and aluminum kick plates, I pretty much got all the options that were available.

2007 Nissan Altima - Front View
2007 Nissan Altima - Rear View

 These photos were taken at the parking lot of the office building I work in.

Tomorrow (Saturday), I’m going to have the windows tinted :)


Update: 9/15/2007

I opted for medium tint for the driver and front passenger windows and dark for the rear passenger and rear windshield. Here’s what it looks like now:
2007 Nissan Altima - Right Side with Tint
2007 Nissan Altima - Left Side with Tint
2007 Nissan Altima - Left Side with Tint
2007 Nissan Altima - Rear with Tint





New Blog

13 09 2007

I was going to write my own blogging application, but as you can see that didn’t happen.  I used to have a blog at the ASBESTOS site, a guild of friends and gamers for those that don’t know.  I wanted to separate that site from my random thoughts.

So here we are today, a fresh start.  Now I just need to update the link on Dev-Geek.com to point to this blog site.

Posts prior to this were imported from my previous blog sites.