CK's Tech Blog
It's Microsoft's World, and I'm just living in it

How To List All Session Variables ASP.NET

August 6, 2008 06:00 by ckincincy

Recently I needed to display all Session Variables when a crash would happen.  A crash would happen and I have this website I was working on send me an email with the stack trace and now the session variables.  However I wasn't aware of how to list all session variables, so I went to my friend Google and came up with the following code:

string strSessions;
for(int i=0;i<Session.Count;i++)
{
       strSessions += Session.Keys[i].ToString() + " - " + Session[i].ToString() + Environment.NewLine;
}

Works like a champ!

HT: davidj.org


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Response.Redirect, Server.Transfer

August 2, 2008 06:00 by ckincincy

After recently launching a website, I had some built in error reporting in it.  Starting seeing a few 'Thread is being Aborted' errors.  I remembered dealing with this at my previous job and that it was related to the Response.Redirect call.

So hopefully with the help of a few of my readers we can put a list of issues related to the various calls that you can make to redirect a user to another page.

Response.Redirect
Response.Redirect was something I first used in classic ASP.  now due to the nature of that platform I didn't see any issues with it.  But in .NET its a different story.  Microsoft gives us a few versions of this call.

1. Response.Redirect("URL")  - The parameter is just the URL that you want the user sent to.  Pretty strait forward.
2. Response.Redirect("URL", true/false) - The second parameter is what causes the error above.  By default version one of this call sets the second parameter to true.  However what that does is 'abort the thread' so as your page goes down to the next call it will see that the page is being aborted.  By setting this to false, you fix the issue.  However this is not idea because by setting it to true you are getting a bit more overhead on your HTTP traffic because you are telling the server to continue the request. Even though you have moved on.

Server.Transfer
Server.Transfer is a lot like Response.Redirect in that you have two versions to call.

1. Server.Transfer("URL")
2. Server.Transfer("URL", True/False) - The second parameter determines whether or not you can use the objects (like text boxes) on the original page.  If it is set to true, you can use the objects.  If it is set to false, you can't.  Those items expire when the new page loads.

Comparisons
Now from my reading there are a few other distinct differences between the two.

1. Response.Redirect allows you to redirect to pages external to your site. The Server.Transfer HAS to be on your server.
2. Server.Transfer is just like Response.Redirect with a true passed in.  Except it doesn't throw the original error.  This allows you to save server resources as you transfer from page to page.

Well do you have anything to add?  Did I miss anything?

HT: Microsoft
HT: Karl Moore


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Refactoring Code

July 29, 2008 06:00 by ckincincy

When I started at my new job I inherited a website that was, to put it mildly, written poorly.  Unfortunately due to the nature of a fast paced business you can't always take the time to make code right.  You have to just pile bad on top of bad because it works.

However recently I took the time to refactor a page.  Before starting it had 2,411 lines of code... after I was done, 649!!!  What used to be a pain to add onto or edit, is now a breeze. 

So when the time is write, refactor.  It makes life a lot better.  Better yet... write it right to begin with!


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Windows Always On Top

July 25, 2008 06:00 by ckincincy

image One feature that I use to increase my productivity is an application called AlwaysOnTop.  Basically it adds a menu to the right click on the title bar to make a window 'always on top'.

This allows me to open up one document (lets say a tutorial on how to do something in Visual Studio) and make it 'on top' while I have my IDE open to walk through the tutorial.

There are a lot of similar applications out there, but none of them that I've found are are good as this one.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Uninstalling .NET framework

July 21, 2008 06:00 by ckincincy

I've had two interesting things happen to friends computers over the past few months.

First I got an email from my friends at Tin Roof (by the way, if you want to support a great charity... this is it) telling me that she needed to file an extension on her taxes before she leaves for Nicaragua on Tuesday. However when she started Turbo Tax she was getting an error.

Further investigation by me (via a VNC connection I set up with her a while ago) realized that this was a .NET error.

Turbo Tax spit out the following error: 20888 39915.  A Quick search of their site gave this article.  Basically blaming .NET and their solution has a link to a program that totally wipes out .NET from your system so you can start over.  I downloaded the program, ran it and then reinstalled .NET and her problem was fixed (well after I ran a reboot.bat file that was in the Turbo Tax installation folder, but that's another issue all together).

Then I have another buddy who had been using a program I wrote for my church to transfer files between members of the multimedia team.  Several months ago a basic Windows component of it stopped working right.  I was at a total loss for a solution (as a simple uninstall and reinstall of .NET didn't help).  I let it drop... but I emailed him today with this fix and my hunch is, that this will get him up and running again.

What frustrates me the most about this, is that Microsoft's .NET uninstall doesn't fully uninstall itself.  Many years ago I did some work for Lexmark's All in One printers and one of the BIG things they did was make sure that their uninstall completely wipes out any record of the machine being on your system.  And really there is no excuse for any other behavior.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

DateTime.ToString() Patterns

July 17, 2008 06:00 by ckincincy

Many times when programming in .NET you need your DateTime variable to display in various formats:

08/22/2006
Tuesday, 22 August 2006
etc...

This is thankfully made pretty trivial with the ToString() function.  Just pass in the appropriate format string and you will get what you need.

You can find a great list of these here.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Firefox Bug

July 13, 2008 06:00 by ckincincy

Well this post is somewhat an archive for me in case it returns, but it may help somebody else.

Occasionally when I click external shortcuts on my system I will get the following Windows error:

"Windows cannot find 'www.example.com'. Make sure you typed the name correctly, and then try again."

Turns out this error is due to a Firefox 2.x bug.  Now I am not sure if it happens on 3.x (which I am running, but it is certainly something you can face on 2.x).

The fix involves a registry hack, but if you have any technical knowledge you can do it pretty easily.

View the fix.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories: Firefox | Microsoft
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

.NET Search Engine

July 9, 2008 06:00 by ckincincy

If you are a .NET developer you've faced the issues I've faced when using a major search engine... results that don't really fit your problem.

But Google has an interesting feature that allows you to create a custom search engine.  You define the sites it searches. 

Dan Appleman has put together a site www.searchdotnet.com that searches his list of .NET sites and overall the results I get from this site are pretty good.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Interviews and Recommendations

July 5, 2008 14:48 by ckincincy

It has been an interesting week for me.

Started off with an old coworker IM'ing me and asking if I'd be a reference for a job he was interviewing on.  I certainly said yes, and last word I got is that he got the job.  The email I sent in reply to the email looking for feedback was a glowing recommendation for somebody who is a very skilled developer, and my first mentor in the trade.  Its good to be able to give back to him at times.

Then I was tasked with tech interviewing a candidate for a job at my employer.  First real interview I've had to do.  Was fun. In the end I love programming and talking about programming is pretty fun as well.

Next I was talking to a dad of one of my daughters friends.  He was recently back from a 10 month tour in Iraq.  He is a true, decorated war hero.  But now he has to reintegrate back into the real world.  Part of that is him wanting to get an IT job in the area.  He is interested in a newbie position, but some of his skills are a bit above that as well.  He has secret security clearance.  He'd be good for any company that needs general IT help (server setup, maintenance, deployment, help desk related work).  So if you work for a company that could honor one of our war hero's AND get a new worker at the same time... let me know and we can talk.  I have his resume on hand.

Finally came the most interesting part of the week.  We needed another .NET developer (we had hired the one I interviewed previously) for my employer and I recommended a former co-worker whom I helped train in what was nice and  good about programming.  This is a guy who at one point thought x was a valid variable name.... still can't believe that first code I saw from him... From what I can tell salary arrangements have been agreed on and if the owners of the company approve, me and this fellow will be co-workers once again. 

This final guy is one where I put my reputation on the line for him.  I am very tight lipped about my recommendations.  There are just four guys who would get my unequivocal recommendation.  There are many others who would get a recommendation on their work ethic, ability to learn, etc... but just four who I would recommend for ANY job they were going for.  He is one of them.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Working with Zip files in .NET

July 2, 2008 06:00 by ckincincy

Recently I was working on a project that required me to unzip a file and process its contents.

But I needed to first figure out how to unzip a file.  To the rescue came the SharpZipLib.  This is under the GPL but is specifically released for personal and commercial use.

In my very basic use it worked like a champ.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5