Category: Code


If you want to quickly delete all the bin and obj folders in a solution:

  1. Right-click on the solution in Solution Explorer
  2. Open Command Prompt
  3. Run powershell
  4. Paste and run this:  Get-ChildItem -include bin,obj -recu -Force | remove-item -force -recurse

FizzBuzz in one line

Subtract 10 pts if you actually implement anything like this in real life code:

using System;
using System.Linq;
 
namespace FizzBuzzInOneLine
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            Console.Write( String.Join("\n",
                Enumerable.Range(1, 100)
                    .Select(x => (x%3 == 0) 
                        ? (x%5 == 0)
                            ? "FizzBuzz"
                            : "Fizz"
                        : (x%5 == 0)
                            ? "Buzz"
                            : x.ToString())));
          }
     }
}

Free multi-server caching from Microsoft

Caching is absolutely the most effective way to speed up the performance of an app.  However, .NET does not have a reasonable tool for caching data, such as the contents of a database table, across all servers for all users.*  There are third party tools that do this, but they are pricey.

A tool called AppFabric is available from Microsoft (for free) that spans the cache for all users across all web servers in a farm/garden/cluster.  Downside: it’s only available for current operating systems like Windows 7, Vista, and Server 2008.

If you’re interested, here are some tutorials:

http://msdn.microsoft.com/en-us/library/ee677288.aspx
http://msdn.microsoft.com/en-us/library/hh334305.aspx
Universal Caching solution

A breaking change in ASP.NET 4.0 causes a javascript error to be thrown on a page if a query string has a “potentially unsafe” character, such as an apostrophe in a last name.

You’ll see the error (possibly only while debugging): “A potentially dangerous Request.QueryString value was detected from the client” when passing the special character in a query string in a button click or a jqgrid’s FillGrid postData BuildGrigArgs function.

The fix is easy:  set the behavior back to ASP.NET 2.0 in the web.config with this line in the system.web section right below your </compilation> tag (the requestPathInvalidCharacters parameter here blocks everything except a single quote):

 <httpRuntime requestPathInvalidCharacters="&lt;,&gt;,*,%,:,&amp;,\" requestValidationMode="2.0" />

And in your pages be sure you don’t encode the parameter in the MVC code in your javascript (i.e. you’ll need to use <%= instead of <%: for those parameters that need special characters). 

For example, this:

    function BuildPreviousArgs() {   

            var args = new Object();

            args.FilterLastName = "<%: Model.FilterLastName %>";

            return $.param(args);

        }

Has to be changed to this:

    function BuildPreviousArgs() {   

            var args = new Object();

            args.FilterLastName = "<%= Model.FilterLastName %>";

            return $.param(args);

        }

© 2013 Robert Corvus