Permanent (301) redirect in IIS

Need send all the traffic from and to the same place?

This is a very common request, and it is very easy to do.  Not to mention it is great for SEO.  To do this, it is quite simple.


  1. In IIS, find your webiste you want redirect, right click and choose properties.
  2. Click the 'Home Directory' tab and click on the 'a redirection to a URL' radio button
  3. Enter the address to redirect to and check the 'A permanent redirection for this resource'


And you are done.

Getting 404 errors when downloading certain file types?

Recently, in our in-house file repository (.net based) we were getting errors 404 when trying to download .iso files, the fix is quite simple

All other file types were downloading just fine, .exe, .jpg, .gz, etc. but .iso files would produce a 404 error.  They were linked to with a simple <a href="file.iso">file.iso</a> and I checked and double checked that the files were there and the links were correct, but it still wouldn't work.  The problem is, that in order to be able to download a file as a file, it must be a registered MIME type in IIS.  The default list is pretty thorough, but some file types are left out, as was the case with .iso.


Here is how you do it:


  1. In IIS Manager, right click on your server and choose properties
  2. Click MIME Types
  3. You will see the list of registered MIME types, and your desired file extension will not be in the list (check to make sure)
  4. Click New and enter the extension in the Extension field (.iso in my case) and the description in the MIME Type field
  5. Apply and the restart IIS (iisreset in command prompt)


That is all you need to do. To set it per web site, right-click the site and select properties, then navigate to the HTTP headers tab.  From there select MIME Types at the bottom and add the desired MIME Type as necessary.

Free Glassy Button Generator with Rollover

I am a graphical Neanderthal, this simple tool helps me make fancy 'glass' buttons - easy to slice and use for sliding doors as well

Pretty much explains itself, this site makes glassy buttons easy, just provide the colors and dimensions (text if you want) and you are done.  This is a nice tool to use as you can just make one image without text and slice the end off for use with sliding doors - that way you don't have to make 500 images for your site, just a few depending on verticle sizes/colors.  The tool also provides you with rollover changes, pretty slick.  The downloadable .zip includes .png, .jpg and .gif files.

Converting an Excel Spreadsheet to a DataSet, DataTable and Multi-Dimensional Array

A way to easily manipulate data from an excel spreadsheet programmatically

I work in an office environment which is dominated by Microsoft Excel spreadsheets, and so often, people want to use them in programs.  I am a SQL junky myself, but Excel is appropriate in a lot of cases, but integrating them into programs can be a pain.  More specifically, getting the data from the Excel worksheet to a form where it is workable can be a pain. 


With this example, you can see how to take in an Excel Spreadsheet to get the data into commonly manipulatable data types in c#; then you can use/change it however you want to.  This demo shows first how to put the data into a dataset, then datatable (almost the same thing), then takes the same data in puts it into a multi-dimensional array (I prefer to work it arrays).  Since this is a linear progression, the demo only outputs the information from the array into an html table to show that it worked. 


The demo uses the very first row as the column names (as it is used in datatable) and assumes that the Spreadsheet is in default format with Sheet1 as it's first sheet.  The demo only processes Sheet1.  This can be easily customized if you want to process more. 


With this, you can take/change/display the excel data however you want to using controls like ListView or GridView or just simple c#.  The code is pretty well commented, so you should be able to pull the parts that you may need.  *NOTE: you need full trust enabled for this to work properly.

Errors when publishing an open social google gadget

Simple fixes to simple errors when just starting out with open social widgets 

Just made my first basic open social gadget for Daily Atheist Quote and ran into an error which I couldn't find any documentation (I didn't really look all that hard).  Basically I tried to publish my first widget from the Google Scratchpad and I got this warning:

Please consider fixing the following issues below before publishing your gadget:

    * Author attribute is missing or undefined.
    * Author email attribute is invalid or undefined.
    * Height attribute must be defined.
    * Width attribute must be defined.
    * Description attribute is missing or undefined.
    * Thumbnail attribute must be defined and set to a valid image URL.

Couldn't figure out where this stuff actually went.  Turns out after messing around, it really was very simple and I just had to stick that info into the ModulePrefs:



<ModulePrefs title="Daily Atheist Quote" description="Rotates Atheist Quotes Daily"
    title_url="" author="Stan Naspinski"
    author_email="" height="200" width="300" >



And that is it, your Widget should now validate through the Scratchpad Publishing just fine.

HTML/JavaScript Dropdown List Redirect

Recently on a forum the question was asked how to redirect using a dropdown and not using any server side scripting - the answer turns out to be pretty simple

All that is needded is a simple Javascript function that takes in a drop-down list as an input, takes the value of the selected option and run it through a location.href.  Here is the JavaScript:

function Navigate(drop_down_list) {
   var number = drop_down_list.selectedIndex;
   location.href = drop_down_list.options[number].value; }

Then all you need to do is add a dropdown list setting the values to the urls you want to navigate to, and the onclick event set to Navigate(name_of_dropdown) and you are all ready to go. Here is a quick example:

Rounded Text Box Inputs - Slick looking and customizable

Great looking 'web 2.0' (god I hate that term) rounded textboxes - fully adjustable to the length of your textbox using css 'sliding doors'

 I saw some of these rounded textboxes somewhere (?) and I though they looked pretty good.  Even though they don't really go with any of my sites, I wanted to know how they were done.  I figured the easiest way to get them working without making a ton of images would be to use CSS sliding doors technique I picked up from a while back (awesome site!). 


The finished product looks pretty good, uses strictly html and css (asp controls work great too) and really couldn't get much easier.  It works for single-line textboxes as well as checkboxes.  You could easily take the concept to a multiline textbox if you just added some larger images.  The code is pretty self-explanatory, so I won't get into the details here.  I included the .png files so you can customize the colors if you want - just drop in the code and go.

Simple Mail Classes - Easiest way to send email and/or gmail via

two classes that you customize and put into your App_Code folder which will allow you to send email with less code and greater ease than ever before

I have all sorts of programs that need to send email, whether its my own project (I use gmail) or a work project (local smtp). I got tired of what was essentially the same code filling up large chunks of my codebehinds.  I had error pages emailing our dev team, registration pages emailing event coordinators, and things such as that - that can turn out to be a lot of code; not even to mention if something needs to be changes on any sort of scale.  So, I made a couple classes that make it even easier to send mail throughout my apps, and this is all you need for code to send an email:

email message = new email();
or, for gmail:
gmail message = new gmail();

It is really that easy, you don't even need to include System.Net.Mail; in your page.  But that is using the default settings which you set the first time you set the code, it is just as easy to define many other aspects of the emails, such as to, from, subject, body, etc.  But the beauty comes with the default settings so you code can be as clean as possible.


Say you usually send your system emails from the address , the subject/body is usually "System Error", the recipient is most often, and your SMTP will likely always be the same (as I would assume it would) - simply set that as your default_from, default_subject, default_body default_to, and default_SMTP to those values, and you will need nothing other than the above code to send an email.  But say on the same app, you want to send something to you want the subject to be "complaint" and the body to be something you collected from a TextBox (txtComplaint) control in your code - that is no problem at all

email message = new email("", "complaint", txtComplaint.Text);

All the other default settings will still take place unless you override them, and all settings can be overwritten.


There is also a few methods added like .addTo(string emailAddress) and .addCC(string emailAddress) which do exactly what you would think they do.  The gmail class works exactly the same as the email class.


It's no coding breakthrough, but it is convenient!



kick it on

SQL Search Control for your page using :: code

Providing only keywords, this tool will write a simple search query, run it, and display your results; lightweight and easy to customize; in both control form, and standalone page

I was tired if writing SQL for doing simple queries on my databases, especially when they got loooong... so I ended up writing a program to do it for me.  Now this is in no way a complex search tool, but it does its job.  It does use 'LIKE' as I needed it to search text fields, but you can change that out if you want - this will get you started.


All you need to do to get it running is to provide 3 values: 

  1. Either your DB ConnectionString, or the name of that ConnectionString in your web.config
  2. The name of the table you wish to search
  3. The column names you want to compare to the search terms

And that is it.  The search is delimitted by [space], [comma], [semicolon], and [plus-sign] and each keyword must show up in at least one of the fields in order for the search to return results.


I provided both a standalone page that runs the search on itself, and a control version that consists of a user control that you can insert anywhere, and a search.aspx page that will show the results.  The control is very versatile. 


This is a good starting point if you want to expand on it.  I made a fully customized search at work starting with this with multiple dropdowns, fields and textboxes, all built on this basic architecture.  Play around with it and tell me what you think - I would even write a tutorial on how this thing works if anyone is interested.

Iconize Textlinks with CSS

This is a great way to add a little visibility to your users, it adds an icon next to your file links, showing them visually what it is

I take no credit at all for this, all the credit belongs to 


This is a great tool - and very simple when you look at it I got rave reviews when I implemented this on our in-house web-based fileshare system at work.  Hopefully it can help you out too!