OCDProgrammer.com

It's Microsoft's World, and I'm just living in it
View Clarence Klopfstein's profile on LinkedIn

Clarence Klopfstein's Facebook profile

This site is under construction...

Categories

New Comments

Referring Sites


Disclaimer

  • This is MY blog. The views represented here are not in relation to anybody else. Please read my full disclaimer for a more complete disclaimer.

Failed to access IIS metabase

August 10, 2008 03:00 by ckincincy

At work we've recently hired a few new developers and they got this error.

Having worked at setting up many development boxes in the past I knew what the issue was, but honestly I need to post about it so I have a quick reference to the fix... and I figured it may help you as well.

The problem?  .NET framework was installed before IIS.  The fix is pretty easy, you need to 'reinstall' the .NET framework.  Thankfully Microsoft makes it fairly easy.

Open up a command line and type the following and you will be good to go.

c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis.exe -i

Which will look something like this after the fact:

image

More info here.


How To List All Session Variables ASP.NET

August 6, 2008 03: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


Response.Redirect, Server.Transfer

August 2, 2008 03: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


Refactoring Code

July 29, 2008 03: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!


Uninstalling .NET framework

July 21, 2008 03: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.


DateTime.ToString() Patterns

July 17, 2008 03: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.


Working with Zip files in .NET

July 2, 2008 03: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.


Math with Doubles and Decimals in .NET

June 28, 2008 03:00 by ckincincy

Just before I went on vacation I had an interesting issue at work.

I was trying to multiple an int by a decimal.  Nothing big, but I kept getting this error:

Operator '*' cannot be applied to operands of type 'decimal'

I was floored, what do you mean I can't multiply a decimal in .NET?  What in the world are you talking about?

So after a brief search I found the fix.

Basically I had to add an M to the decimal.  So instead of:

4 * .95

I needed:

4 * .95M

Honestly still don't understand WHY Microsoft would think this is required, but they do. 

Hope this helps you as it helped me.

HT: Asp.net