Posted by: alivemedia | November 27, 2007

Cookie.Path FTW!

So I am working on a site that uses a customer membership provider I wrote so I can use my own database schema.    Pretty simple, I added in a feature where in the config you can pick which table and  fields to select from the database as well as a list of cookies to set when a user logs in.  This makes it easy for me to use on any database I end up with, here is the web.config:

<membership defaultProvider=EcommerceMembershipProvider>
<providers>
<
add name=MyMembershipProvider type=MyMembershipProvider connectionStringName=myConnectionString membershipTable=Customer username=EmailAddress password=Password setAdditionalCookies=True cookieList=EmailAddress, CustomerID, ShipState selectFields=EmailAddress, Password, CustomerID, ShipState/>
</
providers>
</
membership>
 

As you can see I am setting 3 cookies, EmailAddress, CustomerID, and ShipState.  So far so good.  

I also needed a feature in the admin of the site so the site administrator could easily log as differnt users by click a special link in the admin – here’s where I started getting very weird behavior. 

The auto login page I link to loads, calls my membership provider, logs the user in, sets the cookies and redirects to the page I want.  This works great on FF, not so much on IE 7.  I noticed that I always had 2 sets of cookies, one for the administrator that was logged in (admins use the same membership provider but have a different role assigned to them) and one for the user that I tried to auto login as. 

But this only happens in IE 7?

It was always my understanding that setting a value of a cookie that already exists overwrites the value that was currently there, not creates a second duplicate.  And this was only happening in IE 7.

Here is my code for setting the cookies from my membership provider:

HttpContext.Current.Response.Cookies(cookieName.Trim).Value = dr.Item(cookieName.Trim).ToString
HttpContext.Current.Response.Cookies(cookieName.Trim).Expires = DateAdd(DateInterval.Month, 1,
Date.Now)

Seems like it should work to me?  I search everywhere, just Google actually, and couldn’t find anyone having a similar problem.  I came across the Cookies Overview page at MS and it occured to me that maybe the cookie path for these sets of cookies differs for some reason.

So I added the following to my cookie setting code:
HttpContext.Current.Response.Cookies(cookieName.Trim).Path = “/store”

Problem solved!  Not exactly sure why, but hey IE 7 now works.

If anyone has any insight as to why this might happen please let me know.

kick it on DotNetKicks.com

Posted by: alivemedia | November 7, 2007

Honda Classic Site Launched

We finally launched the new Honda Classic website the other day, check it out: http://www.HondaClassic.com

It came out pretty slick, some pretty funky CSS stuff going on here along with some nice PNG transparencies. Man I cannot wait until IE 6 is gone for good – who knows how long that will but I can dream at least.

Posted by: alivemedia | November 7, 2007

Hello world!

Well I finally broke down and decided to create a blog, mostly because my girlfriend is sick of hearing me blather about ideas I have for programming and website stuff I find totally interesting.

I will probably mostly be posting about other posts I have found interesting and decided to integrate into my programming. Since I am the only programmer at my office this will hopefully give me a place to vent and get some creative feedback.

Anyways here goes!

Categories