Subscribe: David Findley's Blog
Added By: Feedage Forager Feedage Grade B rated
Language: English
background color  background  color csharpcode  color  csharpcode color  csharpcode  margin csharpcode  net  new  sel  string  system  web 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: David Findley's Blog

David Findley's Blog

My little home in the cloud.


Certificate error with Web Platform Installer

Tue, 09 Mar 2010 01:49:00 GMT

 A friend of mine was having an issue getting the Web Platform Installer to work on his Windows Server 2008 R2 box. He said there was some sort of cert error and asked me to try on my local machine to see if I got the cert error.  I tried it and I did get a cert error on Windows 7 64bit. I happened to notice that that url simply redirects to . Out of curiosity I dropped to a command line and tried to run .\WebPlatformInstaller.exe /? to see if there were any command line options. It gave an error that said invalid URI. So we tried running it with the product list url like: "WebPlatformInstaller.exe" . This seems to get around the expired cert that is on

 Here's a screen shot of the error:


ASP.NET MVC – Multiple buttons in the same form

Sun, 31 May 2009 13:04:00 GMT

I keep seeing this question in forums and on twitter so I thought I’d post all the various ways you can handle this and what the pros and cons are. The Scenario Imagine you have a user signup form. There are several textbox fields for entering the new account information and then two buttons: Signup and Cancel. Signup will process the account information and Cancel will return the user to the home page. Option 1 – Each button submits the form but provides a different value ~/Views/Account/Register.aspx 1: <% using (Html.BeginForm()) { %> 2:
4: Account Information 5:

6: 7: <%= Html.TextBox("username") %> 8: <%= Html.ValidationMessage("username") %> 9:


11: 12: <%= Html.TextBox("email") %> 13: <%= Html.ValidationMessage("email") %> 14:


16: 17: <%= Html.Password("password") %> 18: <%= Html.ValidationMessage("password") %> 19:


21: 22: <%= Html.Password("confirmPassword") %> 23: <%= Html.ValidationMessage("confirmPassword") %> 24:

25: 26: 27:

30: <% } %> ~/Controllers/AccountController.cs 1: [AcceptVerbs(HttpVerbs.Post)] 2: public ActionResult Register(string button, string userName, string email, string password, string confirmPassword) 3: { 4: if (button == "cancel") 5: return RedirectToAction("Index", "Home"); 6: 7: ViewData["PasswordLength"] = MembershipService.MinPasswordLength; 8: 9: if (ValidateRegistration(userName, email, password, confirmPassword)) 10: { 11: // Attempt to register the user 12: MembershipCreateStatus createStatus = MembershipService.CreateUser(userName, password, email); 13: 14: if (createStatus == MembershipCreateStatus.Success) 15: { 16: FormsAuth.SignIn(userName, false /* createPersistentCookie */); 17: return RedirectToAction("Index", "Home"); 18: } 19: else 20: { 21: ModelState.AddModelError("_FORM", ErrorCodeToString(createStatus)); 22: } 23: } 24: 25: // If we got this far, something failed, redisplay form 26: return View(); 27: } The downside to this solution is that you have to add some yucky conditional logic to your controller and all the form data has to be submitted to the server just so the server can issue a redirect. To make the controller code a little better you could implement a custom ActionMethodSelectorAttribute like this: 1: public class AcceptParameterAttribute : ActionMethodSelectorAttribute 2: { 3: public string Name { get; set; } 4: public string Value { get; set; } 5: 6: public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) 7: { 8: var req = controllerContext.RequestContext.HttpContext.Request; 9: return req.Form[this.Name] == this.Value; 10: } 11: } 12: Now I can split into two action methods like this: 1: [ActionName("Register")] 2: [AcceptVerbs(HttpVerbs.Post)] 3: [AcceptParamet[...]

ASP.NET MVC ModelState should work like TempData

Fri, 13 Mar 2009 23:16:00 GMT

I prefer to have the actions that forms post to just process the posted data and then redirect to a different action for viewing the results. So in order to pass validation errors back to the form action I need ModelState to work like TempData does. In fact it seemed that before ModelState was added that one of the most common scenarios for using TempData was passing validation error messages between actions so I’m not sure why it doesn't already work like this. I’m using RC2 so its doubtful this will change before RTM. :(

Anyhoo, this code totally saved me:

Interesting finds 3/13/2009

Fri, 13 Mar 2009 22:23:17 GMT

As soon as I get some time I need to look at these a little closer:

Merry Christmas Indeed!

Thu, 27 Dec 2007 03:37:00 GMT

Janice went all out this year and got me an Ibanez JS1000 (Joe Satriani series) guitar, a Line 6 POD X3 Live effects board and a pair of Roland CM-30 amplified monitors. My fingers are all tore up now since I've been out of practice for some time now. But it sure is fun to get back to some jamming. The JS1000 is pretty light and has easy action. Combined with the POD X3 I can get quite a variety of amazing sounds. I even got the X3 hooked up to my MacBook Pro and finally was able to try out Garage Band. I was able to lay down the rhythm track for Crushing Day (what I could remember from back in the day) and then play the lead part over it with no lag. The roland CM-30s are nice because I can run my Alesis QS8 and the POD X3 into them at the same time. This is probly the best setup I've ever had.

Later today I hooked up a microphone to the X3 and the kids had a blast talking and play singing into it. "Daddy it sounds kinda like I'm in a cave...". Perhaps I should cut down some of that reverb. :) 

Santa Clause was good to me this year. (Thanks Janice)

LINQ - The Uber FindControl

Fri, 29 Jun 2007 14:14:00 GMT

With a simple extension method to ControlCollection to flatten the control tree you can use LINQ to query the control tree:

public static class PageExtensions
    public static IEnumerable All(this ControlCollection controls)
        foreach (Control control in controls)
            foreach (Control grandChild in control.Controls.All())
                yield return grandChild;

            yield return control;
Now I can do things like this:
// get the first empty textbox
TextBox firstEmpty = accountDetails.Controls
    .Where(tb => tb.Text.Trim().Length == 0)

// and focus it
if (firstEmpty != null)

Pretty cool! I can do all sorts of querying of the control tree now. LINQ you are my hero.

A Quick Fix for the Validator SetFocusOnError Bug

Fri, 29 Jun 2007 14:03:00 GMT

The ASP.NET validators have this nice property called "SetFocusOnError" that is supposed to set the focus to the first control that failed validation. This all works great until your validator control is inside a naming container. I ran into this recently when using validators in a DetailsView. Take this simple example:<%@ Page Language="C#" %>
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } If you run this page and do a view source you'll see that the FirstNameTextBox gets rendered like this: If you just do a post back without entering a value to cause the validator to fail it will output this line of java script in an attempt to set the focus to the invalid element:WebForm_AutoFocus('FirstNameTextBox'); .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } See anything wrong with this? It would seem that the validators just use the string[...]

VS.NET Macro To Group and Sort Your Using Statements

Thu, 08 Feb 2007 04:20:01 GMT

I try to follow a coding standard for organizing my using statements. System.* goes at the top and then other namespaces grouped together like this: using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Web; using System.Web.Script.Services; using System.Web.Services; using System.Web.Services.Protocols; using Microsoft; using Microsoft.CSharp; using MyCompany; using MyCompany.Web; .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } I finally got tired enough of keeping this all sorted out that I made a VS.NET macro to do it for me. This macro will take the current selection, parse it for using statements, group and sort them like the above example. Here's the macro code: Dim _usingPattern As Regex = New Regex( _ "\s*(?using\s*(?\w+)[^;]*);", _ RegexOptions.IgnoreCase _ Or RegexOptions.Multiline _ Or RegexOptions.ExplicitCapture _ Or RegexOptions.CultureInvariant _ Or RegexOptions.Compiled _ ) Public Sub SortUsing() If Not DTE.ActiveDocument Is Nothing Then Dim sel As TextSelection = DTE.ActiveDocument.Selection If sel.Text.Contains(vbCrLf) Then If sel.ActivePoint Is sel.BottomPoint Then sel.SwapAnchor() sel.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn, True) sel.SwapAnchor() sel.EndOfLine(True) Dim groups As New SortedList(Of String, List(Of String))() For Each match As Match In _usingPattern.Matches(sel.Text) Dim u As String = match.Groups("using").Value Dim g As String = match.Groups("group").Value ' System usings sort at the top If g = "System" Then g = "_" + g Dim list As List(Of String) If Not groups.TryGetValue(g, list) Then list = New List(Of String)() groups.Add(g, list) End If list.Add(u) Next Dim builder As New StringBuilder() For Each group As KeyValuePair(Of String, List(Of String)) In groups If builder.Length > 0 Then builder.AppendLine() group.Value.Sort() For Each line As String In group.Value builder.Append(line) builder.AppendLine(";") Next Next sel.DeleteLeft() sel.Insert(builder.ToString()) End If End If End Sub .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpco[...]

Fix ReturnUrl When Sharing Forms Authentication with Multiple Web Applications

Tue, 06 Feb 2007 17:01:00 GMT

Scenario: You have two web applications and The login site provides a centralized login application and www contains any number of web applications that should use the auth ticket issued by the login site.

The auth ticket can be setup to be shared across the two 3rd level domains no problem. The problem with this setup is that when the user requests a page on www and gets redirected to login the ReturnUrl query string parameter contains a relative path. As far as I know there are not any extensibility points on the FormsAuthenication or FormsAuthenticationModule classes that you can use to fix this. A quick and dirty fix is to use the EndRequest event in your global.asax like this:


   1:      protected void Application_EndRequest(object sender, EventArgs e)
   2:      {
   3:          string redirectUrl = this.Response.RedirectLocation;
   4:          if (!string.IsNullOrEmpty(redirectUrl))
   5:          {
   6:              this.Response.RedirectLocation = Regex.Replace(redirectUrl, "ReturnUrl=(?'url'.*)", delegate(Match m)
   7:              {
   8:                  string url = HttpUtility.UrlDecode(m.Groups["url"].Value);
   9:                  Uri u = new Uri(this.Request.Url, url);
  10:                  return string.Format("ReturnUrl={0}", HttpUtility.UrlEncode(u.ToString()));
  11:              }, RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  12:          }
  13:      }

The basic idea is to intercept the redirect and process the returnurl query string parameter with a regex. This could also be wrapped up in it's own HttpModule. It's kind of cheezy I know but it seems to work.

A VS.NET Macro to Generate Machine Keys.

Tue, 06 Feb 2007 02:26:00 GMT

I needed to create a new machine key for an site. I found a couple of command line utils out on the web that would create a new key but I thought it would be easier to just have it avail in VS.NET. So, I threw together this little macro that will generate the machine key and insert it. Just run the macro while you have you web.config open in VS.NET. If you already have a machinekey it will find it and replace it. If not it will just add it right after the node. It should do the proper indents and everything too. 1: Imports System 2: Imports EnvDTE 3: Imports EnvDTE80 4: Imports System.Diagnostics 5:   6: Public Module AspNetUtils 7:   8: #Region "Helper Code" 9:   10: Dim _rng As New System.Security.Cryptography.RNGCryptoServiceProvider() 11:   12: Private Function GetRandomData(ByVal size As Integer) As Byte() 13: Dim randomData(size) As Byte 14: _rng.GetBytes(randomData) 15: Return randomData 16: End Function 17:   18: Private Function ToHex(ByVal data() As Byte) As String 19: Dim sb As New System.Text.StringBuilder() 20: For i As Integer = 0 To data.Length - 1 21: sb.AppendFormat("{0:X2}", data(i)) 22: Next 23: Return sb.ToString() 24: End Function 25:   26: Private Sub WriteNewMachineKey(ByVal sel As TextSelection) 27: sel.Insert("", vsInsertFlags.vsInsertFlagsContainNewText) 36: sel.Unindent() 37: sel.Collapse() 38: End Sub 39:   40: #End Region 41:   42: #Region "Macros" 43:   44: Public Sub GenerateMachineKey() 45: If Not DTE.ActiveDocument Is Nothing AndAlso DTE.ActiveDocument.Name.ToLower() = "web.config" Then 46: Dim sel As TextSelection = DTE.ActiveDocument.Selection 47:   48: If sel.FindPattern("\", vsFindOptions.vsFindOptionsFromStart Or vsFindOptions.vsFindOptionsMatchInHiddenText Or vsFindOptions.vsFindOptionsRegularExpression) Then 49: ' Replace an existing element 50: sel.Delete() 51: WriteNewMachineKey(sel) 52: ElseIf sel.FindText("", vsFindOptions.vsFindOptionsFromStart Or vsFindOptions.vsFindOptionsMatchInHiddenText) Then 53: ' insert the new machineKey just after the element 54: sel.Collapse() 55: sel.NewLine() 56: WriteNewMachineKey(sel) 57: Else 58: ' no element found so just collapse the current selection and insert 59: ' the new key at the cursor location 60: sel.Collapse() 61: WriteNewMachineKey(sel) 62: End If 63: End If 64: End Sub 65:   66: #End Region 67:   68: End Module .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpco[...] is live.

Sat, 03 Feb 2007 00:34:34 GMT

We recently launched our video tutorial site for Expression Web Designer. Dustin, our resident graphic artist is pumping out the video tutorials as well as designing the site using the tool. It's good to have some how to vids from a designers point of view. Watch this site throughout 2007 as he continues to expand the content.

Scott Guthrie presents at NDDNUG

Fri, 03 Nov 2006 03:03:59 GMT

Scott gave a whirlwind presentation to a standing room only crowd at the North Dallas Dot Net User Group tonight. A wide range of topics were covered from IDE tips and tricks to ASP.NET tips to MS AJAX to LINQ and DLINQ (I still like to call it DLINQ rather than LINQ to SQL). I'm still not sure how all this got packed into a little over 2 hours. :)

This was the first meeting that I've attended at the new Intuit location. It was quite an upgrade in venue from the previous SMU campus location. Lots of projector screens and flat panels so it was very easy to follow along even if you were in the nose bleed section.

While there's a ton of cool things going on with AJAX, seeing LINQ in action again reminds me of just how revolutionary LINQ is.

So, thanks for the great presentation Scott and don't be a stranger to Dallas! :)

Parallels adds "Express Windows Installation"

Thu, 02 Nov 2006 20:27:25 GMT

I just ran across this over on parallels site:

This sounds like a great feature for their virtualization product. Parallels for OSX is a top notch virtualization product and they just keep on adding features.

Using IronPython for Dynamic Expressions.

Thu, 02 Nov 2006 15:22:13 GMT

We recently had this question posted to our forums over at LVS: Dear Forum Experts: I am looking for very specialized solution: I have various Items which I store into a table in a Relational DB.I would like to do a custom calculation, specific for each item at it's instance. Because the calculation is specific for the item, and items are soo many I wold like to store the calculation formula into a relational DB. The problem is to convert the string of formula into a real programming command and to actually perform the calculation. I do not want to use Excel or additional software in order to gain calculation speed e.g. ItemID = 5001, ItemSize = "a - b"ItemID = 5002, ItemSize = "a - 2*b"ItemID = 5003, ItemSize = "a + b" So, ItemSize is actually the formula expression that would calculate various instances of a and b variables ... I have tryed this: int a = 10;int b = 5; string formula = "a + b" // This comes from ItemSIze of DB,SQL, etc. int Result = a + b; // This is a second line for test only - hard coded... int CalcResult = int.Parse(formula); //I wish this was working ... MessageBox.Show(Result.ToString()); // This works ...MessageBox.Show(CalcResult.ToString()); // Never got that far. The result will be stored in different DB with the instances of a and b.Could you please post any information on how should I approach this problem. Thanks a lot. Several options immediately came to mind: code up a simple expression interpreter, evaluate the expression with dynamic SQL (yuck), use lightweight code gen. Then I remembered this little thing I saw at last years PDC called IronPython. Solving this problem with IronPython was "like butta". using System; using System.Collections.Generic; using System.Text; using IronPython.Hosting; namespace PythonDemo { class Program { delegate int MyExpressionDelegate(int a, int b); static void Main(string[] args) { PythonEngine pe = new PythonEngine(); MyExpressionDelegate expression = pe.CreateLambda("a + b"); int a = 10; int b = 5; int c = expression(a,b); Console.WriteLine(c); } } } That's all there was to it! The API for the PythonEngine was very intuitive. I could immediately see where and how I could integrate this with any number of applications that I've worked on in the past. Tip of the hat to the IronPython guys! Now I haven't tested this against a simple interpreter but I would imagine as long as you are smart and keep a cache of the expressions and don't re-parse them every time that it would perform just as well as any interpreted solution if not better. Just follow the make it work, make it work right and make it work fast model and you'll be ok. I wonder if this would also be possible by referenceing the PowerShell runtime. I'll have to take a look at that next and see how it compares. P.S. Microsoft, if you're listening, please include IronPython in the Orcas/NETFX3.5 release! :) I'd love to see IDE support for python scripts and such.[...]

Suggestions for distributing CTPs as VirtualPC images

Wed, 25 Oct 2006 02:36:32 GMT

I finally got around to trying the Sept. CTP of Orcas. I loaded up the VPC images on VPC7 Beta (which seems to perform much better than VPC2004). If this is going to be the way that MS is going to release CTPs in the future here are a few suggestions:

  • Don't have undo disks enabled. This just slows things down. If I hose out the vm image I can redownload from MSDN or just recopy it from a backup. This just makes things slow.
  • Don't install every single option of VS.NET. Are there really CTP changes to Crystal Reports in this release? This is just a waste of hard drive space and makes the experience more frustrating.
  • Tweak the .vmc files so that they don't have some MS developers local paths to the E drive in them. This makes the end user have to relocate the hard drives on first launch. This is a little thing but its so simple to fix why not do it.
  • Please, please, please allocate more than 384M ram for a VS.NET + SQL + IIS install. At least up it to 512M. I would not advise that anyone run the Orcas CTP in less than 512M ram. It was painfully slow on my 2 Ghz Core Duo MacBook Pro. I quickly upped it to 1Gig allocation and it was like night and day. I realize that not everyone can allocate 1 gig ram so a better compromise would be 512M. If you only have 512M mem in your host PC then your virtualization experience is going to be horrible anyway. Again this is a small thing but its so brain dead simple it should just be setup correctly to begin with.
  • Make the simple tweaks to make win2k more developer workstation friendly. For example: do we need to have the shutdown logging feature enabled in order to preview a CTP? The performance options were still set to Background Services and System Cache!?! These tweaks could be made to the parent differencing disk at the beginning so that the OS install is set and ready to go for developer use.

One of the advantages of a virtualized CTP is that we developers don't have to sit through an install process. This is negated if we have to do alot of fiddling with the VM settings in order to make it run at an acceptable level.

These are all little nit picks but I think the effort is really small and would give the end users a much better experience when trying out the CTPs.

P.S. also consider using a tool like to shrink down and optimize the vm image. VM Optimizer works wonders for shrinking the size of the virtual machine which in turn improves over all perf.

ASP.NET AJAX 1.0 (excitement builds)

Sat, 21 Oct 2006 03:38:14 GMT

I just downloaded beta 1 of ASP.NET AJAX today. Wow! Lots and lots of changes. The type system has been greatly simplified. I like this. The move to prototypes over closures was a good decision. The core scripts are much easier to read and comprehend as well. The CTP download has been a 404 for me this evening so I haven't had a chance to dive into it.

Looking through the core scripts there seem to many improvements. There used to be a bunch of prototype extensions to the Function object that were really only applicable to ctor functions. This seemed like it was pretty inefficient. That doesn't seem to be the case anymore.

All in all the script library feels less like a hodge podge of techniques from around the web and has more of a cohesive feel to it. Maybe that'll change once I get into the CTP add-ons. Overall I'm impressed with what I've seen so far. This definitely seems like a big step forward.

We used the CTPs for some back-end admin functionality on so as soon as I can lay my hands on the new CTP bits I'll have to see what the migration process is like.

Ok, time to get back to playing... :)


Update: looks like the CTP download is working now. I think its going to be a long weekend. ;)

What's in a name? The developer vs programmer non-issue.

Fri, 13 Oct 2006 22:11:00 GMT

I remember seeing the "Developers vs Programmers" article on digg recently. I did think at the time that it was a bit over the top. Mike has managed to capture my exact feelings on this subject in this post:

The thing I like most about Mike's post is the theme of "teamwork". There are many aspects to software development. Being a "guru" at all aspects is becoming more and more impossible. It is all to common to think in black and white these days. Every subject seems to be polarized. In my opinion the world is a better place when we treat each other with respect and recognize each others abilities and contributions.

So thanks, Mike, for reminding me that not everyone in the world sees things in such black and white terms.

Apple finally delivers some of my most wanted features...

Tue, 12 Sep 2006 18:21:00 GMT

Looks like the new iTunes will have the cover art browsing that I've been wanting. Also the iPods (and iTunes a guess) now support gapless playback. I have alot of music that really needs this (Pink Floyd, Roger Waters, Rush etc...)

Great interview on IronPython...

Sat, 09 Sep 2006 20:23:00 GMT

I just watched this interview on IronPython:

This is really great stuff and it reminds of why its such an exciting time to be a developer on the MS platform.

Convert Thunderbird Email to Windows Mail

Wed, 06 Sep 2006 03:15:35 GMT

I've been converting my thunderbird email boxes to Windows Mail on Vista. To do this you need to use a tool that convert the mbox format to .eml format. I found this free one that seems to work pretty well:

Just follow the instructions in #3 "Convert mbox files to eml files" and then drag the .eml files into the apropriate folder in Windows Mail.