Quick Update: CSS/JS Auto-Minification in ASP.NET

I’ve been trying for weeks to write up a good technical article about a recent CSS/JavaScript minification handler for ASP.NET (ASHX/HttpHandler) that I whipped up, but our current release has been so busy, I haven’t had enough time to really put it all together.

Just wanted to post a quick update for everyone who mentioned they’d like to hear about it that I’ll be posting more info as soon as I can. =)

In the meantime, here are links to some of the articles that helped me construct the custom handler in the first place:

And, my own pride and joy (this damn code took me forever, only because I had to do all sorts of research and testing with Regex in C#), the function that will fix relative paths in the combined CSS files by replacing them with absolute paths based on your application root:

/// <summary>
/// CSS Only: Replaces relative paths in url(...) properties within the specified script.
/// </summary>
/// <param name="scriptBody">The pre-combined script, passed from CombineScripts().</param>
/// <param name="scriptPath">The relative path where scripts are located (ex: ~/CSS/).</param>
/// <param name="applicationPath">The absolute application path. (ex: /ApplicationRoot).</param>
/// <returns></returns>
private static String FixRelativePaths(String scriptBody, String scriptPath, String applicationPath)
{
 scriptPath = VirtualPathUtility.AppendTrailingSlash(scriptPath);
 String relativeRoot = VirtualPathUtility.Combine(applicationPath, scriptPath);

 Regex cssUrlReference = new Regex("(?<=url\\()(.+?)(?=\\))", RegexOptions.Singleline);
 Regex invalidPathChars = new Regex("[ '\"]+", RegexOptions.Singleline);

 MatchCollection urlMatches = cssUrlReference.Matches(scriptBody);
 foreach (Match m in urlMatches)
 {
 String oldPath = Regex.Replace(m.Value, "[ '\"]+", "");
 String newPath = VirtualPathUtility.Combine(relativeRoot, oldPath);
 newPath = VirtualPathUtility.ToAbsolute(newPath);
 scriptBody = scriptBody.Replace(m.Value, newPath);
 }

 return scriptBody;
}

I’d love to read your comments and/or questions about this code, so please feel free to post your thoughts in the comments on this post.

I’ll try to get you the full meal deal on this code as soon as I can. =)

KB971092 won’t install (Visual Studio 2008 Security Fix)

From Microsoft Connect:
(https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=478117)

Until Microsoft come up with an official solution there is a working workaround for this problem.

This problem only appears to affect people who have not got Visual C++ Installed.

1.) Download VS90SP1-KB971092-x86.exe from here …
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=294de390-3c94-49fb-a014-9a38580e64cb
2.) Start the installation VS90SP1-KB971092-x86.exe
3.) Wait for the error message to come up – DO NOT CLOSE THE WINDOW!
4.) Copy the temp. folder where the patch has been unpacked to a new folder, for example onto your desktop.
5.) Close VS90SP1-KB971092-x86.exe that you started in 2.)
6.) Navigate to <drive>:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools and find vsvars32.bat.
7.) Change the permissions on the file to allow everyone to edit it.
8.) Start VS90SP1-KB971092-x86.msp from within the saved folder and the process should complete.

jQuery fadeIn/fadeOut IE cleartype glitch

Thanks to Benjamin Michael Novakovic for this fix!

While using the jQuery  javascript library today at work, I noticed a glitch under IE7. When fading a html node with the .fadeIn() and .fadeOut() functions in jQuery, IE drops the windows Cleartype rendering; which results in very ugly text. This problem appears to be very common, but no one has a nice solution for the problem.

The most common way to solve this problem is by removing the filter CSS attribute. In normal javascript, it would look like this:

document.getElementById('node').style.removeAttribute('filter');

and in jQuery, it would look like this:

$('#node').fadeOut('slow', function() {
   this.style.removeAttribute('filter');
});

via Benjamin Michael Novakovic » jQuery fadeIn/fadeOut IE cleartype glitch.

11 Tools Every ASP.NET Programmer Should Install

I found a great list of “6 Free Tools that every Windows Programmer should Install” via a contact of mine on Twitter, which made me want to create my own list, similar to the tools listed in the link above, with a few additions and changes:

  1. Firebug

    If you have Firefox, but you haven’t tried this yet, install it now. You’ll thank me later. Firebug is currently my most essential tool (besides Visual Studio, of course) to web development since it effortlessly debugs JavaScript and shows you the ins and outs of the DOM on any page you’re inspecting. Firebug is available as an extension for Firefox, or as a bookmarklet for any other browser.

    It’s also worth noting that Safari and Chrome (well, anything rendered with Webkit, it seems) have an excellent set of development tools built-in that are very similar to the functionality of Firebug in Firefox, and even IE8 is catching up to the game with its Developer Tools window/pane.

  2. Unlocker

    I agree with Ian, this program is excellent. Gives you some useful information for a change (and something you can do with it) when you get the message “Cannot delete <X>: It is being used by another person or program.”

  3. TortoiseSVN

    If you’ve been using Subversion for source control, I’m sure you’ve heard of this client. If not, get it immediately. It rocks, and integrates exceptionally well with Windows Explorer. (Not to mention Visual Studio, via AnkhSVN or VisualSVN)

  4. IETester

    Since Internet Explorer is the scourge of the Interwebs that will never go away, it helps to be able to test your site in multiple versions of IE, and since only one version can be installed at a time (and since IE8 Compatibility Mode doesn’t really help at all), IETester is a good solution that lets you test IE5.5, IE6, IE7, and IE8 rendering engines in the same tabbed browser. Very cool.

  5. VMWare Player

    …But, as my coworker mentioned, Internet Explorer is pretty invasive and modifies more on your system than just the rendering DLLs, so it’s a good idea to keep a spare VM running each flavor of IE as well. VMWare Player is the free version of VMWare Workstation, which will run pre-existing virtual machines, but can’t create new ones. Since that functionality is missing from VMWare Player, you can use this site to create your own virtual machines from scratch: EasyVMX! Virtual Machine Creator.

  6. .NET Reflector

    RedGate’s description says it best:
    “.NET Reflector enables you to easily view, navigate, and search through, the class hierarchies of .NET assemblies, even if you don’t have the code for them. With it, you can decompile and analyze .NET assemblies in C#, Visual Basic, and IL.”

  7. Sysinternals Suite (includes Process Explorer)

    Ian Hickman’s post (6 Free Tools that every Windows Programmer should Install) suggests Process Explorer alone, which is a superior Task Manager replacement, but I’ll extend it to suggest the whole Sysinternals Suite, since it comes with so many other great utilities and includes Process Explorer along with them. One of my favorite tools besides PE is AutoRuns, which is a msconfig.exe replacement that offers a much better look at your startup apps and services.

  8. WinMerge

    TortoiseSVN comes with its own diff tool, but I tend to end up using WinMerge instead because it does a great job with comparing local files or differing versions of a file in source control, and integrates seamlessly with TortoiseSVN.

  9. Launchy

    I’m definitely a keyboard junkie, so anything I can do to keep my hands on the keyboard is a plus. Launchy is by far my favorite application launcher for that reason. All I have to do is hit Alt+Space (you can reassign the hotkey if you like), and it brings up a prompt that allows me to launch anything on my Start Menu, and do a number of other tasks as well (launch websites, perform quick calculations, etc.). Definitely saves me a ton of time.

  10. Charles / Fiddler

    Of the two apps listed above, I prefer Charles, which is a paid application, but I’ve listed Fiddler as a free alternative. Both apps are proxies that log traffic between your system and the server you’re debugging (even localhost) and both provide valuable debugging information that is particularly helpful when trying to debug web services. From the Charles website:
    “Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP traffic between their machine and the Internet. This includes requests, responses and the HTTP headers (which contain the cookies and caching information).”

  11. EmEditorNotepad++ / Notepad2

    All three of the apps listed above are excellent full-featured text editors, but I prefer the feature set of EmEditor, which is a paid application. The killer feature that EmEditor provides which I haven’t yet found in either of the other editors is the Find *and Replace* in files. Notepad++ has a Find in Files option, but I haven’t found a Replace in Files function without opening up every single document and performing a replace in all open documents (info on that approach here: How To “Find And Replace” Words In Multiple Files).

    Notepad2 doesn’t offer the same tabbed document interface that both EmEditor and Notepad++ offer, but it is an incredibly lightweight, and more importantly, self-contained executable that’s a perfect drop-in replacement for Windows Notepad (info on how to do this here: Replace Notepad with Notepad2).

    Any of these apps offer syntax highlighting and are a great alternative to firing up Visual Studio when you need to make a quick edit (or on one of the *many* occasions when Visual Studio slows waaaaay down or locks up your system).

Honorable mention: PhraseExpress
This program rocks. I’ve only started using it recently, and not nearly to its fullest potential, but the clipboard manager functionality alone is worth the download:

Also, I neglected to mention AutoHotkey since I haven’t used it as much as I probably could, but I can say that I’ve had a lot of luck with the AutoHotkey script iTunesAnywhere, which helps since I don’t have a keyboard with multimedia keys and for whatever godforsaken reason, iTunes *still* doesn’t natively support global hotkeys like Winamp does. (I’d switch back to Winamp, but I drank the Apple kool-aid and picked up an iPhone in January.)

#region: Awesome or Horrible?

While coding in Java recently, I decided to do a little research to see if Java supported the #region directive (or something similar) and found a ton of articles knocking its usage as poor programming style.

Personally, I love the #region directive in C#, as it allows me to keep my code more organized (and yes, I am aware of the exisiting code-folding functionality in Visual Studio). In the files I work with, I’ve become pretty meticulous about organizing the code blocks into regions, partially because I like the organization, and partly because I was previously under the impression that it was good form to keep source files organized in this way. I use the following regions myself, generally:

  • Private/Protected Members
  • Public Accessors
  • Constructors
  • Public Methods
  • Protected Methods
  • Private Methods
  • (Anything class specific)

I agree with the sentiment in the articles I’ve read that it is *not* good practice to sweep bad code under the rug by hiding it from the developer in a folded #region, but I think that organizing relatively good code into regions like the ones I’ve mentioned above makes it a lot easier to get directly to the code I want to work on.

What do you think? I’m curious to see justifications for/against this directive, and as always, thanks for reading!

Additional links:

ASP.NET: Starter Kits and Community Projects

In relation to the last post, here are some starter kits and projects officially listed at Microsoft’s own ASP.NET site (http://www.asp.net/community/projects/)

Starter Kits

 

DotNetNuke® Web Application Starter Kit

DotNetNuke is an open source web application framework ideal for creating, deploying and managing interactive web, intranet and extranet sites. The combination of an enterprise portal, built-in content management system, elegant skinning engine, and the ability to display static and dynamic content makes DotNetNuke an essential tool for ASP.NET developers.

TheBeerHouse: CMS and E-commerce Starter Kit

TheBeerHouse starter kit enables you to implement a website with functionality typically associated with a CMS/e-commerce site. This website demonstrates key features of ASP.NET 2.0 and is the sample used in the book, “ASP.NET 2.0 Website Programming / Problem – Design – Solution.”

Small Business Starter Kit

The Small Business Starter Kit provides a sample of a business promotion website suitable for small and medium-sized businesses. It provides a template for customizing and creating a site for your own business out-of-the-box, with advanced features including integration with SQL and XML data sources for content and data management.

Open Source

dasBlog

dasBlog is a blogging engine that offers elegant visual aesthetics, powerful easy to use features, and a unique application architecture. dasBlog requires no database engine, using file-based content management with an architecture that ensures excellent performance.

Visit the dasBlog Web Site

ScrewTurn Wiki

ScrewTurn Wiki is a fast, powerful and simple ASP.NET wiki engine, installs in a matter of minutes and it’s available in different packages, fitting every need. It’s even free and open source.

Visit the ScrewTurn Wiki Web Site

BlogFodder: List Of Free / Open Source ASP.NET Web Applications

I started looking for free/open-source ASP.NET applications to run on my development instance of IIS (since IIS is already running on my machine), and stumbled upon this list today:

As a big ASP.NET advocate, I’m loving the recent surge in open source / free ASP.NET applications that are hitting the web – And what’s more because Microsoft have given us some great building foundations with the frameworks like the ASP.NET Membership Provider, a lot of these open source programs are very high quality!  More so than some of the paid applications.

I thought it would be a good idea to create an ever growing list of all the open source ASP.NET applications I could find – Obviously I haven’t had chance to download or install every application so I can’t vouch for them

Notable applications:

Full list available at:
http://www.blogfodder.co.uk/post/2008/07/List-Of-Free–Open-Source-ASPNET-Web-Applications.aspx)

Making XAMPP (Apache) work with IIS on Windows XP/Vista

Update: This application will help you track down which applications are using which ports on Windows – very helpful for debugging if the steps below don’t solve your problem, or if IIS is not the only application answering on port 80: http://winnetstat.zapto.org/

Also, if you don’t specifically need all the features of XAMPP, but would like to run PHP/MySQL applications through IIS, give Web Platform Installer a try. Through WPI, you can choose to install PHP directly within IIS (so that IIS can serve both ASP.NET and PHP applications on port 80, for example) and you can also have a ton of applications installed and configured automatically for you, such as Drupal, WordPress, and Moodle (among many others). However, if you are still looking to run XAMPP specifically, or just run an Apache instance along with IIS, check out the instructions below. Thanks for visiting!

Continue reading “Making XAMPP (Apache) work with IIS on Windows XP/Vista”

Super Nintendo Emulator SE

Just found out about this today – I was always curious as to how they developed games for the Super Nintendo…

emuse2

Super Nintendo Emulator SE

From Wikipedia, the free encyclopedia

The Super Nintendo Emulator SE was a Nintendo-sponsored game development system for the Super Nintendo Entertainment System. It was designed by Intelligent Systems, and sold only to licensed Nintendo development houses.

Physical views

The device is in the form of a large, rectangular metal box, approximately 18 inches high, and 12 inches wide, and 13 inches deep. The box is painted grey, and bears the marking “Emulator SE” on the front in grey.

The device has two controller ports at the bottom that are standard Super Nintendo Controller ports. The rear of the device featured two 50-pin SCSI interface designed to connect to a PC running MS-DOS. One of these ports came with a terminator. The rear of the device also has a port labeled “Multi-Out”, which is identical to the Multi-out port on a normal Super Nintendo.

Below that, it has an 8 position DIP switch. Because there is no known copy of the documentation of this machine, the function of the switches is unknown. Although it is possible the switch is used to set the SCSI ID of the device.

The units bear five-digit serial numbers.

The device is rated to consume 40 watts of power at 120v, and bears a 1991 copyright date. It uses a standard PC Power Cable.

Wikipedia article here:
http://en.wikipedia.org/wiki/Super_Nintendo_Emulator_SE

Some pictures here:
http://shiggsy.gbadev.org/unit.php?unit=22

More info here (from an owner of the system):
http://dforce3000.de/snes.html

Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!

Great post on how to share a solution between VS2008 and VS2005, from stevenharman.net/blog:

One of the things I’m most excited about with Visual Studio 2008 is it’s ability to target various versions of the .net framework, a feature known as multi-targeting.

I recently rebuilt a (hand-me-down) laptop for use at developer group meetings, conferences, and coding from the couch. When building out the machine I decided to only install VS2008 and make use of multi-targeting to work on my various .net 2.0 projects… like Subtext. Today I finally got around to loading Subtext up in VS2008 and I was expecting some heartache.

But I did a little research first and luckily came across Rick’s great post explaining how VS2008 and VS2005 can be made to play nice together, allowing you to work with your projects in either IDE. The gist is, the project files (i.e.- your .csproj files) will work in either environment, but you’ll need to maintain separate solution files. Not a huge deal as most of the churn is usually in the individual project files, and not the solution.

(via Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!)

Regarding Base-64: Trying to solve an ASP.NET issue…

Update: Thanks to WordPress.com automagically linking related posts to each other, I think I may have found a potential solution to this issue here: Invalid character in a Base-64 string (ASP.NET)

The problem seems to be with the ViewState. The ViewState is encrypted, and when an attempt is made to decrypt it on postback, the error is triggered.  The solution is actually quite simple: in the web.config file, set the ViewState not to be encrypted, like this:

<system.web>
<pages viewStateEncryptionMode=”Never”>
</pages>
</system.web>

You should really check out the rest of that article; it looks like it’s got a great explanation for what is actually occurring.

Also, this seems to be related to another message, “Invalid Viewstate.”

My original article is below the fold…

Continue reading “Regarding Base-64: Trying to solve an ASP.NET issue…”

Performance and Editor fixes for VS2008…

KB946581 Install

In regard to my previous post, Visual Studio 2008 Is Pretty Damn Slow, a couple engineers from Microsoft have contacted me to let me know that a hotfix has been made public which should address the performance issues I mentioned in that previous post.

The blog entry regarding this hotfix can be found here:
Downloadable Hotfix: Performance and Editor fixes for Microsoft Visual Studio 2008 and Visual Web Developer Express 2008

More info from Scott Guthrie’s Blog:
VS 2008 Web Development Hot-Fix Roll-Up Available

More info from Rick Stahl’s Blog:
Visual Studio Hotfix for Slow Web Forms Editing and Input Focus Issues

And the hotfix itself, here:
Connect.Microsoft.Com (DownloadID=10826)

Quote from the MSDN blog linked above (Downloadable Hotfix…):

Continue reading “Performance and Editor fixes for VS2008…”