IIS 6.0 serving unknown file extensions?

by aherrick 17. November 2008 10:25

We were working on a web project that was served on IIS 6.  In the code, we were creating our own extensions (.BUYER, .PACK., .ITEM) for example.  The problem occurred when these files became unavailable for download when running the site through IIS. 

"Internet Explorer cannot download X"

iis6 cannot download

The solution was simple. 

  1. Open IIS, right click on the local computer name and select properties.

iis 6 properties

    2.   Select "MIME Types"

    3.   Select "NEW"  

    4.   Input the extension and application/octet-stream for MIME Type.  If you want to allow ALL extensions, add an asterick (*).

iis6 mime type

That simple!  Good luck :)

Tags: ,

C# Twitter Extension

by aherrick 29. September 2008 15:06

I was looking for an easy solution to add Twitter to my blog, and decide to write a class extension to fit my needs.  With input from Fence Row Productions I came up with a class to easily grab your most recent tweet and display it on your blog.  The code will parse Twitter API to display your most recent Tweet.


Check out how I am currently using it.

Added two ASP.NET label controls "lblTweet" and "lblTweetInfo." Also added an image control "imgTweet."

Here is my current code behind file for my MasterPage.  The class constructor is your Twitter login name (twitter.com/you)

   imgTweet.ImageUrl = "~/pics/twitter_bird_32.png";

   Twitter t = new Twitter("andrew_herrick");
   this.lblTweet.Text = t.TweetStatus;
   this.lblTweetInfo.Text = 
        string.Format("<a href='{0}' target='NEW'>{1}</a> from {2}.", 
        t.TweetURL, t.TweetDateDiff, t.TweetSource);
 

Attached is the complete class. Let me know how it goes and enjoy!

Twitter.cs (4.65 kb)

Tags:

C# Get Date Difference

by aherrick 5. September 2008 04:21

I was working on my Twitter extension to display my most recent tweet and I wanted to display how long ago I tweeted.  I was able to acquire some code which I tweaked a bit to fit my needs.  Check it out!

This method accepts two dates that you want to compare.  For example: In my case, date1 is "DateTime.Now" and date2 is the Tweet date (whenever my most recent tweet was).  I will have a full post on the twitter extension you see above soon!

Take a look at the code below!

    private string GetDifferenceDate(DateTime date1, DateTime date2)
    {
        if (DateTime.Compare(date1, date2) >= 0)
        {
            TimeSpan ts = date1.Subtract(date2);
            // if more than 1 day ago
            if (ts.Days > 0)
                return string.Format("{0} days, {1} hours, {2} minutes", 
                ts.Days, ts.Hours, ts.Minutes);
            else
                return string.Format("{0} hours, {1} minutes", ts.Hours, ts.Minutes);

        }
        else
            return "Not valid";
    }

Tags:

Pure CSS Rollover Popup Effect

by aherrick 2. September 2008 11:25

The other day we had a request from a client to provide a rollover effect to display data.  They only wanted it to display when a text area was hovered.  One of my coworkers and I came up with a solution that fit our needs.  I tweaked it a bit from using a DIV to using links and span tags. This makes it more flexible. Here is what I came up with. This solution that is cross-browser compatible.

HTML

CSS

First I start by setting up the link.  The point of setting the z-index is to make sure the "popup" effect floats above all other elements on the page. 

I am made two classes, rollover for the link and tooltip for the text to show.  This will distinguish between other a link and span tag attributes on the page. 

Initially the span tooltip is set to not display.  The final part of the CSS is what the span tag looks like when the link is hovered.  This is where there is a lot of flexibilty on how you want your tooltip to look.  I positioned the tooltip absolute based on the relative position of the link. 

I played with the colors and padding to come up with something I liked.  This can be changed to fit your sites needs of course.

Here is the full code for your enjoyment!

PureCSSRolloverPopupEffect.zip (2.28 kb)

Tags: ,

Ajax Control Toolkit Autocomplete Extender Weird Issue

by aherrick 20. August 2008 05:08

Okay I was working on testing the Autocomplete Extender on a site I am working on.  I noticed something interesting when testing the search functionality.  Take a look at what was going on:

Here is what the control source looked like:

As you can see, the SKU codes I was looking for started with "TEST". But if a bunch of junk text was included before the actual SKU, it would stay with it in the dropdown list.  I finally found the solution by removing the "DelimiterCharacters" from the control.  I hope this works for you!

On an unrelated note I accepted a full time position at Blue Horseshoe Solutions today, I am thrilled.

Tags: , ,

Validate Page on Submit Before Custom Javascript

by aherrick 12. August 2008 23:55

I was working on form submit where I wanted to prompt with a simple Javascript confirm dialog when the user clicks the submit button on the form.  Naturally, all the form fields (name, adress, etc.) I setup using required field validators.  My custom javascript confirm originally looked like this.

 

I called the javascript from the code behind.

The big problem I found was that the javascript confirm function was being called regardless of if the page completely validated or not.  I wanted the functionality to first validate the page, then if the page was valid, run the custom code.   I came up with this code using Page_IsValid.  It uses Page_ClientValidate() to validate the page, then I check if the page is valid.  Simple yet effective! 

Good luck!

Tags: , , ,

Read From XML Using Javascript

by aherrick 8. August 2008 07:08

Today I was working on some code to monitor my network speed (incoming and outgoing).  I wrote a windows service to capture my bandwidth and dynamically create an xml file and upload it to my website.  Every 30 seconds (time is totally configurable) I override the exisiting XML with an XML containing a fresh capture of my bandwidth speed.  How I wote the service is another post for another day...  However I do want to share some code I wrote to load the XML and update the text.

Here is an example of the XML file my windows service generates.

bandwidth xml

The XML file is named bandwidth.xml

I wrote a javascript function to attempt to read the XML file when it is in the same directory as my html file. See javascript function parseXML below.

bandwidth javascript

At the end of the function I make use of setTimeout to call the function again the function after a period of time.  In this case every 10 seconds.

I load the Javascript function using the body onload event.

body onload="parseXML()"

I have three span tags in my html.  XML, upload, and download.  I grab their IDs in the function and use innerHTML to replace the text.  Try it out by loading the html in a browser and changing the xml values.  Have some fun with it!

Check out the XML and HTML below to see the full code.  Good luck!


bandwidth.xml (100.00 bytes)

index.html (1.43 kb)

Tags: , ,

Encrypt and Decrypt Connection String in web.config

by aherrick 23. July 2008 03:55

It can be a good idea to encrypt your connection string before deployment of an web application in ASP.NET.  Plus, it's easy!  Let me show you how.

In command prompt (start -> run -> cmd) navigate to your Asp.Net directory usually found at %WINDOWS%\Microsoft.Net\Framework\version

If you have already setup your application in IIS use the following synatx to encrypt:

aspnet_regiis -pe "connectionStrings" -app "/YourApplicationHere"

Similarly to decrypt:

aspnet_regiis -pd "connectionStrings" -app "/YourApplicationHere"

One thing to note, make sure you are encrypting the connection string on the production box. It will not work to encrypt your connection string on another box and move your web.config into production.

Let me know if this worked for you!

Tags: ,

creating a SubSonic partial class

by aherrick 21. July 2008 00:54

I have been working with SubSonic for almost a year now and I love it.  If you don't know, SubSonic is a data access layer that will automatically generate code to access your data along with a bunch of other really cool tools.  Created by Rob Conery, check him out if you have not, version SubSonic 2.1 was just released.  I'm going to try and blog about different things I pick up about SubSonic that I hope proves to be useful. 

Creating a partial class to extend a a generated SubSonic class is easy!  Let's take a look...

When creating SubSonic based projects, we like to create a class library to abstract SubSonic from the web project.  You can name this project whatever you like.

 In this example I am going to use the Products table from Microsoft's Northwind database.  In my SubSonic project class I create a new folder to hold my partial class.  I call the folder "DAL" 

Create a new class in your DAL folder with the same name as the SubSonic class.  For example, SubSonic generates "Product.cs".  If you wanted to extend this class, the only trick is to put the keyword "partial" in your new class.  See below.

I am going to write a simple method to extend the generated SubSonic Product class.  This method "GetProductsToOrder" will return a collection of products where UnitsInStock is less than 20.  Of course this is just an arbitrary business rule used as an example.  See the code below. 

Now to use this method, since I made it static, I do not have to create a new instance of Product.  I will set it equal to a ProductCollection and pass it an integer.

Now I have a collection of Products with less than twenty units in stock!  Good luck writing your SubSonic partial classes and let me know how it goes!

Tags: , ,

javascript validate textbox onblur

by aherrick 9. July 2008 05:12

Today I was working on some code and I needed to validate a textbox input when the user attempted to leave the field.  The javascript event onblur fit the bill nicely. 

In the code behind I wired up my textbox like so:

this.txtAmount.attributes.add("onblur", "validate()");

This will hook the onblur event onto the textbox programatically.  I find it appropriate to add events progrmatically since Visual Studio complains about adding events to the markup.  While this will still compile and run just fine, there is much more flexiblity in adding events in the code behind.

Now for the javascript code.  First I am setting a reference to my textbox and a hidden field on the form.  The first check is a regular express to make sure my input is valid.  I am looking for positive amount.

For example: 2 valid, 200 valid, 200.20 valid, 200.233 invalid, -200 invalid. 

If input does not pass the regex, I throw an alert asking for valid input.  If it passes regex, my second check is just some business logic.

That is all it takes to write a custom javascript validation for your code. Thank you!

Tags: , ,



Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen
Tweaked by ajondeck.NET

About the author

Andrew Herrick
I am a full time developer for Blue Horseshoe Solutions based out of Carmel, Indiana. I enjoy learning new technology and hope to give back with some of the cool things I pick up along the way.  Check me out on Stack Overflow!


Categories

None

Recent comments

Comment RSS

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in  anyway.

© Copyright 2008