Posts

Showing posts from July, 2009

Simple ASP.NET Localization

Image
I've seen a lot of solutions for localization in ASP.NET -- many of which use a database to store the localized content. The problem with this approach is that you have to recreate the tools that you are already using. Specifically: text editors (now you need an admin site to update the database content), source control (now you need revision history), content uploading (now you need an SSIS or custom Windows Service to deploy content). It's a bigger project than you want. Generally, whenever HTML goes into a database (apart from a Forum), I question the need. The reason being that HTML is code and code belongs in Source Control. If Developers are the only ones updating the content (we're not talking about CMSs here) then why force them to use tools they aren't familiar with to do the same job they do all day long? A solution that I've found that works well is to use an HTTP Module and a Localized directory of files. First, let's go over the HTTP Module.

Unsvn - a way to un-checkout an svn repository

Sometimes other developers push up .svn directories to production. This drives me nuts. Not only does it create clutter but the directory contains sensitive information about where your SVN repository is located and who the user is. Removing these directories is a pain to do manually, so why bother? The C# code below will remove all .svn directories & all the files beneath them for any given path. See the source below or just download the Windows Binary . using System; using System.IO; namespace UnSvn { class Program { static void Main(string[] args) { if (args == null || args.Length != 1) { Usage(); return; } DirectoryInfo root = new DirectoryInfo(args[0]); try { if(!Process(root)) { Console.WriteLine("Nothing to do"); } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } } static void Usage() { Console.WriteLine("usage: unsvn [/path/to/direct

Syntax Highlighting in Blogger -- with jQuery & SyntaxHighlighter

There are a few reasons I decided to go with Blogger over other blogging options. 1) I want to spend time writing not setting things up, 2) BlogEngine.NET didn't seem to look right no matter what theme I used and I didn't like the admin and 3) Wordpress is all MySQL. That being said I wanted to get SyntaxHighlighter working. After reading Guogang Hu's post about how to get it working (& not likely a lot of code), I decided to do it with jQuery. The real issue with SyntaxHighligher and Blogger is the line breaks. Posts have line breaks replaced by <br /> tags -- which SyntaxHighlighter will faithful display. Using the replaceWith method in jQuery makes this a snap. Check out the code below. <link href='/syntaxhighlighter/styles/SyntaxHighlighter.css' rel='stylesheet' type='text/css'/> <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js' type='text/javascript'></script> <sc

Deleting Cookies (or Managing Cookie Domains) in ASP.NET

I just spent a good few hours wrestling with writing authentication cookies in ASP.NET across different sub-domains. I've done enough SSO installations to know how it should work & what the hiccups are. Today I was reminded of a good lesson. I was writing a Cookie out via Response.Cookies.Add() in 2 sites. The problem was the second site was not overwriting the value from the first. So I tried to delete the cookie. I set the expiration to the past, I removed it from the collection, I tried using Klaus Hartl's jQuery plugin . Nothing was deleting this cookie. Then I realized what I was doing wrong -- I was setting the Domain in the first instance but NOT in the second. ASP.NET was using different domains in the cookie. What I learned was that the more general, top-level domain was taking priority over the default domain. Another issue to consider is the fact that Visual Studio 2008 and IIS will read the Cookie values different depending upon their Domain. Let'