The Case of the Disappearing Cookie

If you are working on a site that doesn’t have a proper TLD (i.e. http://localhost:8013) you will notice that setting cookies on the browser doesn’t seem to work the way it should. Sometimes your cookie, which works perfectly fine on a site with a TLD, will not show up on your local site.

For example, this code will work perfectly fine on a site with a TLD but not on your local site.

newCookie = New HttpCookie(ConfigurationManager.AppSettings("YOUR_SPECIAL_COOKIE_NAME"))
newCookie.Domain = ConfigurationManager.AppSettings("BASE_DOMAIN")
HttpContext.Current.Response.Cookies.Add(newCookie)

At this point you might be thinking, ‘I did everything right, where did my cookie go?‘.

This comes down to how the browser handles setting cookies that have a specified domain. The browser prepends a ‘.’ (that’s a dot) to the beginning of any domain specified for a cookie. On normal domains this basically just says that this cookie is valid for this domain and any subdomains. The following non-doctored image proves it:

Set two cookies, one with a specified domain and one without.

Setting Test Cookies
JavaScript to set test cookies for the superfrogadventures.com domain.

This results in the following two cookies

Shows the results of the first cookie set.
Shows the results of the first cookie set.
The Second Test Cookie
Shows that the domain does not have a dot.

You will notice that the domains are a bit different. One has a ‘.’ while the other does not.

So. All this to say, if you are developing locally (or on a site without a TLD) then you will need to save your cookies without a “domain”. This will ensure that the cookie is accessible. Otherwise you will probably need to create yourself some sort of domain with a TLD.

Finding a Column with a Specific Name in TSQL

I just recently ran into a situation where I needed to find a table that contained a specific column in the database. I’m not looking for a column value, I’m looking for the name of the column. So, like any good programmer would do, I spent some time Googling…

There were a number of unhelpful articles and answers on the subject. I sifted through everything and finally landed upon an answer that worked! Unfortunately I forgot where it came from, so if any of you know where this little trick came from feel free to let me know.

In order to find a column with a specific name in TSQL you can use the following query:

USE [YOUR_DATABASE_NAME]
GO
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%[WHAT YOU ARE LOOKING FOR]%'
ORDER BY schema_name, table_name;

Just replace [YOUR_DATABASE_NAME] with the name of the database you are using and [WHAT YOU ARE LOOKING FOR] with the full column name or a part of the column name you are looking for.

Pick of the Week for July 15

Wow, the week has gone by fast. Last week I could hardly wait to post the new pick of the week, and already it’s Tuesday of this week! I blame this partly, or mostly, on selling our home and trying to buy a new one before we have to move out of our current one. If you have never done this before, let me tell you, it’s crazy! The thing is, we really did not want to move into a rental temporarily, we want to move directly into the new house. We only have until 08/15 to find a new place though!

Alright, alright. Enough about me and more about the pick of the week! This weeks pick comes from one of my top 5 all time artists. She quickly gained this spot a few years back and I’m guessing she will retain it for years to come. The artists name is: LIGHTS. And let me tell you, LIGHTS is awesome. She’s kind of like me in that regard.

Several things I like about LIGHTS.

  1. She makes awesome music.
  2. She is a gamer (openly confessing that she loves World of Warcraft)
  3. She is real in the what you see is what you get kind of way.

LIGHTS is a Canadian artist known for her electronic keyboard and synth driven music. Recently she has dabbled in dubstep creating a genre which she dubs “DreamStep”. She uses a Keytar as well as a microKORG (I really wish I had a microKORG actually). In addition to her electronic and synth driven music she is also has some amazing vocals and has released a number of accoustic albums.

The name of the song I’ve picked is “My Boots”. It’s a track that didn’t make it onto her Siberia release, and therefore I didn’t know about it until recently. I like the track because it blends some of her older stuff from “The Listening” with some of her newer stuff from “Siberia“. It’s not like most of the dubsteppish songs on Siberia. It’s got a lighter feel to it.

Take a listen to “My Boots” below and buy it here.

Pick of the Week for July 8th

Has it already been a week since my last pick of the week? Crazy how time flies!

Alright, so within the last week I’ve discovered an artist that I absolutely love! She’s got a great voice and when she sings it just flows like honey. It could also be that she sings in French… and French just seems to flow really well.

For those of you who are wondering the name of this artist is Cœur de Pirate, which, according to WikiPedia, is French for “pirate heart”. Her real name, though, is Béatrice Martin and she is 23 years old. She’s been playing the piano since she was three years old. That’s pretty awesome, I’ve got a three year old and I can’t, at the moment, imagine him sitting still in front of a piano for very long.

The name of the song I’ve picked is, “Saint Laurent”. It’s got some keyboard and accoustic guitar, but the instruments themselves pretty much fade into the background when she starts singing. You can listen to the song below. You can purchase the album or the “Saint Laurent” song here.

Alternative to Eval() and Casting in Databound Control

Some of you might already know this, however I found it interesting and helpful. For the case of this example let’s say you have a Person object defined somewhere in your ASP.NET code.

Public Class Person
	Public Property FirstName As String
	Public Property MiddleName As String
	Public Property LastName As String

	Public ReadOnly Property FullName As String
		Get
			Return String.Join(" ", FirstName, MiddleName, LastName)
		End Get
	End Property
End Class

Say for example you have a collection of Persons that you’ve assigned to a webforms repeater. In your ItemTemplate you would like to access the properties of whatever object you’ve bound to the repeater. .NET 4.5 introduced some new options that allow you to strongly type your ASP.NET data controls.

First let’s go through the way it used to be done…

.aspx.vb File (CodeBehind)

'// declare a list for our repeater to use
Dim persons As List(Of Models.Person)

'// populate the list with persons (returned by this random function, who cares what it does)
persons = _personDAO.GetPersons()

'// assign the list to the repeater and bind 'em up
repPeople.DataSource = persons
repPeople.DataBind()

.aspx File

<asp:Repeater ID="repPeople" runat="server">
	<HeaderTemplate><ul class="people"></HeaderTemplate>
	<ItemTemplate>
		<li class="col_12 peopleWrap">
			FullName: <%# Eval("FullName")%>
		</li>
	</ItemTemplate>
	<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>

You can use Eval to evaluate a string and output the related value like is done in the example above. This uses reflection to figure out what the current object is and outputs whatever property that you’ve specified in your string. This is just a string so you don’t get any intellisense and you have to remember (ugghhh – remembering what’s that?) what properties you have access to.

You can also cast the object to the type you know that it should be. This is nice because it avoids expensive reflection and it also gives us intellisense. After casting you can access the properties normally with intellisense help. (Not to mention warnings and errors should a property on the source object ever change). I.E. Full Name: <%# CType(Container.DataItem, Models.Person).FullName%>
Casting is nice and all, but it can get a bit tedious and messy, especially if you have to cast every time you want to access a property.

Using .NET 4.5 — Strongly Typed Repeaters
However, thankfully, .NET 4.5 decided to help us out and allow us to strongly type our repeaters. This gives us the best of both worlds, we get intellisense, avoid expensive reflection, and also can easily access properties without extensive use of CType. All you have to do is set the ItemType attribute on the repeater itself.

<asp:Repeater ID="repPeople" runat="server" ItemType="Models.Person">
	<HeaderTemplate><ul class="people"></HeaderTemplate>
	<ItemTemplate>
		<li class="col_12 peopleWrap">
			FullName: <%# Item.FullName%>
		</li>
	</ItemTemplate>
	<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>

Pick of the Week for July 1st

Alright, this should be the first of many “pick of the weeks” that I will do. I love music and the pick of the week highlights a song that I like and that you might want to check out.

This weeks pick is the song “Lolita” by The Veronicas. I’ve liked The Veronicas since I first heard them 4 or 5 years ago. One of their songs came up on my Slacker Portable G1 (it wasn’t called the G1 when I got it, it was the new coolness, ok?!) and I was immediately impressed. What I first noticed about their music is that it contains a keyboard/synth sound that just isn’t present in a lot of todays music. In addition to the sweet keyboard sound I was surprised by the vocals. It’s not traditional pop music, these girls know how to sing!

Anyways, I could go on but I’m going to stop here. You can purchase “Lolita” here. The Veronicas are well worth checking out give ’em a listen below.

Dig Web Interface ftw!

Ok. I guess because this is my first post on here I should say something like, “Hi Reader, thanks for stopping by and reading my blog.” So I guess I will.

Hi Reader, thanks for stopping by and reading my blog.

I just wanted to mention really quick how awesome digwebinterface.com is. I’ve used it so many times to find DNS information about different domain names out there. For example, I just now confirmed the DNS information was correct for this blog, jeremysawesome.com.

Confirming DNS with digwebinterface.com
Yep, the DNS for jeremysawesome.com looks correct.

DNS confirmed, jeremysawesome.com is ready to rock!