Showing posts from 2009

S3 Organizer Dialog?

I am copying some of the functionality from this dialog in the S3 Organizer.  I don’t think I will copy these instructions:     {6230289B-5BEE-409e-932A-2F01FA407A92}

WCF with no app.config

I did a Service Reference in my .NET C# assembly and got the infrastructure for a fully enabled WCF proxy.  I also got a app.config file added to my project that I didn’t want.  I need to run configuration free since I am running in both COM+ and managed mode (i.e. some public classes are COMVisible and some are Managed), plus my COMVisible classes are hosted in COM+.  So I need to get ride of the app.config which looks like this:   <? xml version="1.0" encoding="utf-8" ?> < configuration > < system.serviceModel > < bindings > < basicHttpBinding > < binding name = "AmazonS3SoapBinding" closeTimeout = "00:01:00" openTimeout = "00:01:00" receiveTimeout = "00:10:00" sendTimeout = "00:01:00" allowCookies = "false" bypassProxyOnLocal = "false" hostNameComparisonMode = "StrongWildcard" ma

Debugging 0x80070002

0x80070002 is the error code returned when a FileNotFoundException (HRESULT COR_E_FILENOTFOUND) is thrown in managed code.  Basically, there is a missing file that your managed code expects.   In my case I was getting this when I tried to install a component in COM+ (Component Services) where the COM object was written in C#.  However, I didn’t have a method defined as with a [ComRegisterFunctionAttribute], so how could my code throw a file not found exception?  The issue was that my assembly relied on other assemblies that where not present.  Which lead to a binding problem when install the component in COM+, so it was the CLR that was throwing the exception not my code.   To make matter’s worse, I was trying to install the component during an MSI installation.  The .log file from msi just showed an 0x80070002 error.  To find the issue I used the Assembly Bind Log Viewer (FUSLOGVW.exe) found in the Windows SDK.  While the MSI installer ran, The Assembly Bind Viewer was trackin

What is 0x80131501?

When managed code with a COM interface throws a SecurityException the return value (HRESULT) is 0x80131501.  This can happen on a regsvr32.exe (or regasm.exe) or on any method call to the COM interface.   {6230289B-5BEE-409e-932A-2F01FA407A92}

Linking Leaf Nodes In Google Search

I run a travel and tourist site for San Juan Island .  A long time ago we wrote up reviews for all the islands, the major towns, and the high tourism attractions.  The site is structured this way:       We also create a Google Site map giving the home page has the highest priority, the islands the next highest, the cities a lower priority and the individual write-ups the lowest priority.  All pretty standard.  However, when we started to look at the reports from Google Webmaster Tools we saw something very disturbing:     We were telling Google about 220 pages, however only 93 had been indexed.  Why was this?  We presumed it was because there where no external links to the leaf pages (the individual reviews of restaurants, parks, beaches, and trails).  Google crawler was doing exactly what we asked, traverse the high priority pages in the site map and leave the low priority pages.  The leaf pages (the reviews) that were linked externally where being indexed

Amazon EC2 for Windows The Basics – Part VI

The size of Elastic Block Storage (EBS) on Amazon EC2 is charge by the size of the formatted drive, not the size of data on the drive.  In the case of the Windows-Server2008-i386-Base-v101 this is a 30 Gigabytes (the primary hard drive).  Which you pay for regardless if you are using all of it or not.    This is different the the dynamically expanding .vhds that are used in Windows Virtual Server.    EBS storage is allocated all at once to avoid disk fragmentation and poor storage.   {6230289B-5BEE-409e-932A-2F01FA407A92}

Amazon EC2 for Windows The Basics – Part V

What is Elastic Block Storage (EBS)? When the Amazon web site describes EBS there is a lot of references about mounting and raw block storage -- Linux terms. However, with the new boot from EBS for Windows this is a confusing. So from a Windows perspective I am going to try to explain EBS and touch on why boot from EBS is the only way to go for Windows. Windows doesn't really have a concept of mounting hard drives, and the operating system likes all physical drives to be in place before it boots. Which means that when Amazon EC2 boots your Windows instance it needs to know what storage (drives) are attached.  Keep this in mind as you read on. In Microsoft Virtual server we think about this as a .vhd drive. All the virtual hard drives are attached when the Virtual instance is started. Back to Amazon EC2, there are two types of storage (drives) available. ESB drives and Amazon Machine Images (AMI). Amazon Machine Images are stored on the Amazon S3 cloud, and mo

Shortcut of a Shortcut

There is no such thing as a shortcut to a shortcut in the Windows File System.  If you create a shortcut from a shortcut then you just get a shortcut to the original target.  You can programmatically create a shortcut to a shortcut using CLSID_ShellLink, however Windows will not render the icon correctly, or navigate the end target correctly.   {6230289B-5BEE-409e-932A-2F01FA407A92}


  You can not call IShellLink method SetPath with a full parsable path to a namespace extension in Windows 7.  Instead you have to call IShellLink SetIDList.  Once you have set the id list and save the .lnk file via IPersistFile Save method the shortcut will find your namespace extension (on open).  However, CLSID_ShellLink is unable to render the Image via IExtraceImage for the link if the link is to an image (or other file type that supports IExtractImage).  Instead it renders the default icon for your perceived type.  It asks your namespace extension for the perceived type via IShellFolder2::GetDetailsOf.   {6230289B-5BEE-409e-932A-2F01FA407A92}

Creating a Windows Build Server On Amazon EC2

My definition of a build server is a standalone box that has been configured so that it can build a release of your software with one command.  The server typically has compilers, install packing software, and is dedicated to the task of building a release.  Questions from the Joel Test that a build server needs to answer in the affirmative: Build in one step? Daily builds?    My build scripts, that run on the build server, perform these tasks: Clean the Build Directories Checkout all the source files from source control. Compile all the source. Package the binaries and assemblies into installations (setup.exe) Deploy the installations to the download location on the web sever. Update a database (web content server) with version information, download location etc… Over the years, I built different types of build servers, and written many build scripts.  Ten years ago, I had dedicated build servers.  Lately, I use virtual machines hosted on top

Amazon EC2 for Windows The Basics – Part IV

There is a lot of documentation about running Amazon EC2 and if you are having trouble Amazon will quickly direct you to the forums for questions, however there isn’t really a resource from a Windows centric developer to other Windows gurus.  As I 20 year Window veteran, I am going to try to fill that gap with a few blog posts entitled “Amazon EC2 for Windows The Basics”   The second thing I do when install a new windows server is to run Windows Update.    “The second thing that you need to do on your EC2 instance is install the Windows updates.”   The Windows 2003 R2 instances from ESB are recent to the R2 of Windows 2003, however there are a lot of security hot fixes released since R2.  I like to have them all applied.  It is fairly painless since Amazon amazing download times.   Remember this is Windows 2003, so you need to go back to Windows Update every time it makes you reboot until there are no more updates to install.   {6230289B-5BEE-409e-932A-2F01FA407

Amazon EC2 for Windows The Basics – Part III

There is a lot of documentation about running Amazon EC2 and if you are having trouble Amazon will quickly direct you to the forums for questions, however there isn’t really a resource from a Windows centric developer to other Windows gurus.  As I 20 year Window veteran, I am going to try to fill that gap with a few blog posts entitled “Amazon EC2 for Windows The Basics”   Once you have your instance boot, you have retrieved the administrator login from the AWS management console, successfully connected to the server via RDC.   “The first thing to do when you get logged in is change the administrator password”   Amazon provides a good secure password for the administrator account – it is obvious there is a lot of thought put into security.  However, it is a pain in the butt to get the password the first time and to log in.  So changing the password saves you a lot of time on the next boot of the instance.   If you are using Windows you probably already know that you

Amazon EC2 For Windows The Basics – Part II

There is a lot of documentation about running Amazon EC2 and if you are having trouble Amazon will quickly direct you to the forums for questions, however there isn’t really a resource from a Windows centric developer to other Windows gurus.  As I 20 year Window veteran, I am going to try to fill that gap with a few blog posts entitled “Amazon EC2 for Windows The Basics”   I know it is suppose to work, and I know this will get fixed.  However, as of December 2009:   “Sometimes windows instances do not start.”   I don’t want to be negative or point out a bug, however it is really frustrating when you don’t know this might be the case and it happens to you.  It is less frustrating it you know this might happen and what do about it.   The first thing is to figure out if the instance started or not.  The way to do this is look at the system log from the AWS management console.  It should look like something like this:     It should say: “Windows is Ready to use

Amazon EC2 for Windows The Basics – Part I

There is a lot of documentation about running Amazon EC2 and if you are having trouble Amazon will quickly direct you to the forums for questions, however there isn’t really a resource from a Windows centric developer to other Windows gurus.  As I 20 year Window veteran, I am going to try to fill that gap with a few blog posts entitled “Amazon EC2 for Windows The Basics”   For me EC2 is all about replacing servers with cloud computing and when I get rid of my old servers it is my Linux friends that take them.  As Windows IT we always buy the latest and greatest servers and they seem super fast when we buy them.  I get good mileage out of my servers, usually 5 to 10 years.  However, when I go to sell them it seems that they only fetch $50.  However, there is always some Linux geek ready to snatch it up and replace a Pentium 3 server he has in his basement.  Doing so he brags: “I can run 500 web sites on this server” and off he goes into his cave.   The point of this rabble: Windows

Every Exception Has A Unique GUID

If you know me you will know that I love GUIDs and use them for everything.  One of the things I use them for is to create a unique identifier to error messages in my code.  I have override the Exception class adding my own method that looks like this:   public ProviderException(System.Guid error, string message, Exception innerException)     : base(String.Format(CultureInfo.CurrentCulture, "{{{0}}}: {1}", error.ToString(), message, innerException)) { }   Basically, anytime that I want to throw an exception in my code, I do so with a unique GUID.  The calling code looks like this:   catch(SoapException soapException) {     throw (new ProviderException(new Guid("{513EEF48-8C02-4135-9344-2A401EAF2112}"), soapException.Message, soapException)); }   I have the option of creating my own message, and I always pass the exception I am trapping as the inner exception.  Notice that I have a hard coded GUID in my code.  It is not Guid.NewGuid() –

Batch File Bug

This is the code I have:   cd %PROJECTROOTLOCAL%\Installation\AmazonS3\AmazonS3\ del  /s /f /q *.*   What I want to do is delete all files in the Installation\AmazonS3\AmazonS3 directory.  However what if the directory doesn’t exist?  Well I get this error on the first line: The system cannot find the path specified.   And the current directory isn’t changed.  Which leaves me at the root of the my project.  Which means that the second command deletes all the files in my project.  Not good.  The fix is this:   mkdir %PROJECTROOTLOCAL%\Installation\AmazonS3\AmazonS3\ cd %PROJECTROOTLOCAL%\Installation\AmazonS3\AmazonS3\ del  /s /f /q *.*   Or is there something better?   {6230289B-5BEE-409e-932A-2F01FA407A92}

ShortCut Syntax For Command Line

Here is the shortcut syntax I use to get a command line at a particular directory: %windir%\system32\cmd.exe /K "cd \My Projects\BigDrive\trunk\Version 1.0\" This is helpful for having a shortcut pinned to the start menu that opens a command line directly to directory where I run my build commands for my projects. {6230289B-5BEE-409e-932A-2F01FA407A92}

What Is PKEY_ThumbnailCacheId

In Vista and newer Windows operating systems you can implement a IPropertyStore interface for your Shell Namespace Extensions.  One of the things that is asked of your items is what is their PKEY_ThumbnailCacheId.  The PKEY_ThumbnailCacheId is used to determine if the Thumbnail image can be used from the thumbnail cache or if it has to be regenerated by the Shell.  There is no documentation about: PKEY_ThumbnailCacheId.  However in the propkey.h file in the Windows SDK it states:   // Unique value that can be used as a key to cache thumbnails. // The value changes when the name, volume, or data modified // of an item changes.   However, the return value of IPropertyStore::GetValue is a PROPVARIANT, which is much like a VARIANT, it can be almost anything.  So what does the shell expect you to return from the GetValue method when it asks for PKEY_ThumbnailCacheId?  A hint can be found in the definition of IThumbnailCache::GetThumbnailByID method.  The unique identifier

IShellFolderViewCB Is Not Optional

When writing a Shell Namespace Extension with DefView it is important to realize that IShellFolderViewCB is not optional for proper updates of the DefView. If you construct your DefView like this: ::SHCreateShellFolderView(pcsfv, (IShellView **)ppvReturn); One of the parameters of SFV_CREATE is psfvcb which points to an instance of IShellFolderViewCB.  IShellFolderViewCB is a callback interface that you can use to get notified of what is happening in the DefView. If you don’t care what DefView is doing it is tempting to leave it NULL.  However, if you do this the DefView will not update correctly on calls like this: ::SHChangeNotify(SHCNE_MKDIR, SHCNF_IDLIST | SHCNF_FLUSH, *ppidl, NULL); So always implement a IShellFolderViewCB interface with the minimum functionality when using the DefView. {6230289B-5BEE-409e-932A-2F01FA407A92}

Amazon's EC2 Isn't A Good Windows Desktop

It is tempting to think that you could have a configured Windows desktop computer on Amazon EC2 that you turned on whenever you like paying 12.5 cents an hour, then turned off and have it cost you nothing but storage of the hard drive. This computer you could use as a configured desktop with all your favorite applications installed to check email, do work and that you could access anywhere. However, Amazon EC2 isn’t set up that way; in fact it would be very hard to work day to day on an EC2 machine unless you left it turned on constantly. Here are the reasons that Amazon EC2 doesn’t make a good desktop environment: Amazon EC2 only runs Windows 2003 (As of 10/24/2009). Most people are used to a better desktop experience provided by Windows 7, Vista, or Windows 2008 and the Windows 2003 Windows 2003 desktop will feel old to them. When you terminate your Amazon EC2 instance (which stops the meter) EC2 deletes the underlying hard drive and everything that you have saved to that drive

Shutting Down Windows in Amazon EC2

Restarting Windows in Amazon EC2 doesn't terminate the EC2 instance. This is good to know if you are installing software and wonder will the required restart terminate the instance before you are able to Bundle it into an AMI. The answer is no, restarts don't cause termination. {6230289B-5BEE-409e-932A-2F01FA407A92}

Started a new web site yesterday with an idea from Rob S -- it is called and it is using the Stack Exchange technology. Stack Exchange was written by a team at FogCreek Software to run the hugely popular website. Our version of is all about asking and getting answers to puzzles, riddle, and brain teasers. The unique feature of the Stack Exchange technology is that it allows the smartest user to rise to the top with reputation. The whole site only took me an hour to configure in that hour I purchased a domain name, started a Stack Exchange instance and added Google’s AdSense to the web site. Promoting the web site will take me much longer then the technology aspect for this undertaking. If you like brain teasers, riddles and puzzle come visit: {6230289B-5BEE-409e-932A-2F01FA407A92}

Update To MVC's LogOnUserControl.ascx

Microsoft has this code for the LogOnUserControl.ascx partial control when you create a brand new ASP.NET MVC application: <%@ Control Language= "C#" Inherits= "System.Web.Mvc.ViewUserControl" %> <% if (Request.IsAuthenticated) { %> Welcome <b><%= Html.Encode(Page.User.Identity.Name) %></b>! [ <%= Html.ActionLink( "Log Off" , "LogOff" , "Account" ) %> ] <% } else { %> [ <%= Html.ActionLink( "Log On" , "LogOn" , "Account" ) %> ] <% } %> However, this isn't 100% correct. It just so happens that Page.User.Identity.Name in their example is the User's name, however really Page.User.Identity.Name in most cases is a unique (primary) key to a users table. This is a little cleaner: <%@ Control Language= "C#" Inherits= "System.Web.Mvc.ViewUserControl" %> <% if (Request.Is

The Big Idea : Better Password Hashing

For the last couple of days I have been thinking about how browsers send passwords across the network. I think I have a safer way. I would have to work at Microsoft or Mozilla to get this implemented however, I am content with blogging about it and getting some feedback. This is a line of code that as a web developer I write all the time: < INPUT TYPE =” TEXT ” NAME =” Login ” />< br /> < INPUT TYPE =” PASSWORD ” NAME =” Password ” /> This HTML delivers the login and password to the browser in clear text. The web application takes the password and concatenates it onto a stored piece of random text (called salt) and then hashes the complete string. This hash is compared with the hash store for that login and if they match then the web application can assume that the user knows their password. If the web developer implemented good security for his system then he never stores the password, only a hash of the salt and the password. The salt helps make every ha

Twitter And The Courtesy Of Retweeting

Twitter’s strong word-of-mouth characteristics are derived from the common courtesy of retweets of its user base, not on technology – this is changing with an announcement this week. This arbitrary courtesy is the flaw that could lead to its demise once Twitter becomes more commonplace and the tight knit group of early adopters finds that courtesy gets undermined. For example: I have 100 followers and I post an event notification for the small city I live in. One of my followers (call him @WhatcomTravel) decides that this posting is relevant to his/her followers and decides to retweet my posting. By common courteous he starts the post RT: @myusername which gives me credit for the original posting. If he has 2000 followers, some of them will start to follow me to if they feel my postings are relevant to their interest. In essence they go to the source. Here lies the issue; if they follow me it dilutes the attention that they pay to the person that retweeted my post (@WhatcomTrav

Not That Obvious In MVC

I am working on converting some ASP.NET WebForms pages into MVC Views and there are a couple of things I have run across in MasterPages that are not obvious in the beginning. With ASP.NET WebForms if you wanted dynamic content in your MasterPage one way to do it is to have the code behind of the MasterPage insert it, which means that your Page either need to tell the Master Page what to insert or the Master Page need to figure it out. Take this for example: < head > < meta name ="Description" content ="" id ="metaDescription" runat ="server" /> </ head > Here I am trying to add a meta description the head of the HTML so that the search engines know what this page is about. What I was doing is have the page check the type of the master class on the pages OnInit event and if it was the right master class, find the public property in the MasterPage that would set the MetaDescription. When the MasterPage pre-rende

Upgrading WebForms .csproj to MVC

So you followed all the steps to upgrade your old ASP.NET WebForms project to ASP.NET MVC: added the necessary entries to the web.config, created a Views and Controllers directory, and added the necessary references. However, when you right click to add a new item to the Controllers directory (or Views directory) in Visual Studio 2008 there are no MVC items available. You need to update the .csproj view a text editor to "tell" it that it is a MVC project. Here is how: 1. Close out of Visual Studio. 2. Open .csproj file of the web site in notepad 3. In the beginning of file there is PropertyGroup block. Find the ProjectTypeGuids tag. 4. Add {603c0e0b-db56-11dc-be95-000d561079b0} as first project type GUID, the delimiter is a semi-colon. 5. Save the file . Now you can open the solution again in Visual Studio 2008 and you will have the MVC items. {6230289B-5BEE-409e-932A-2F01FA407A92}

Update To RegExRoute Class

Update with a few new constructors that allow you to use the MvcRouteHandler, and some bug fixes. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.Routing; using System.Web.Mvc; using System.Text.RegularExpressions; namespace WebUtility { public class RegexRoute : RouteBase { public Regex Regex { get; private set; } public String[] Groups { get; private set; } private IRouteHandler RouteHandler { get; set; } public String Controller { get; private set; } public String Action { get; private set; } /// <summary> /// Creates A Regular Expression Route /// </summary> /// <param name="regex">Regular Expression To Use Against /// the AbsolutePath of the request.</param> /// <param name="groups">roups In The Match</param> /// <param name="routeHa

Application_Start Only Once

Quick note about Application_Start that I noticed when working with ASP.NET MVC. It gets called only once. Which makes total sense, since the application only starts once. However, it gets run only once even if there is an exception thrown from the code within Application_Start. Which means if RegisterRoutes throws an exception, then you need to trigger the application to reset, otherwise your routes will not be registered on the next call. For Example: 1) You code a new route in RegisterRoutes. 2) Compile 3) You request a page, this calls Application_Start 4) There is an exception in your route and RegisterRoutes throws an exception. 5) You attach the debugger. 6) You request the page again to reproduce the error. This is where you notice that the error doesn't happen again, since Application_Start has already been called and attaching the debugger doesn't restart the application. Here are some of the things I know that restarts the application: 1) Edit the web.config

RegularExpression Routing Class for MVC

I am working with a ASP.NET WebForms website trying to convert it over to ASP.NET MVC 1.0 and need to make sure all the old URLs route correctly. We were using a combination of an HTTPHandler and Custom 404 redirects to give the web site some fancy URLs -- now I need to mimic that functionality with MVC in order not to lose the Google links that the site depends on for revenue. We really only care about the name part of the URI and the hint that it ends in .htm (the .htm extension is mapped to the ASP.NET ISAPI extension handler). So the route I tried to add looked like this: routes.Add( new Route( "{*path}/{name}.htm" , new NameRouteHandler())); However, I got this error message: A catch-all parameter can only appear as the last segment of the route URL. Which was an issue; the path which I tossed away had a lot of optional subdirectories which didn't map well to the MVC Route syntax. What I really wanted was to treat

Enabled RDC in Windows 7

I am running Virtual Server 2005 and just installed my Windows 7 operating system. One of the first things I usually do is install the machine additions however, even with Virtual Server 2005 SP1 they didn't want to install on Windows 7. Without the Machine Additions from Virtual Server the mouse was really sensitive. This left me with a problem -- I needed to enable RDC on the box without using the mouse. Here are the hot keys that helped me from the Virtual Server 2005 web interface to enable RDC: 1) Ctrl-Esc (Brings Up The Start Menu) 2) Right Arrow to the Second Vertical Bar in the Start Menu. 3) Up Arrow to the Computer Menu item in the Start Menu 4) Shift-Ctrl-F10 (Brings up the Context Menu) 5) Down Arrow in the Context Menu till you get to properties 6) Enter (to select the properties) 7) Now you get the Control Panel Properties for the Computer 8) Esc to close the Start Menu 9) Alt-Tab Until you select the Control Panel Properties Window 10) Tab a couple of times until yo