<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>Rob Bihun</title>
    <description>Software Developer in Birmingham, AL</description>
    <link>http://blog.robbihun.com/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.NET 1.5.0.0</generator>
    <language>en-GB</language>
    <blogChannel:blogRoll>http://blog.robbihun.com/opml.axd</blogChannel:blogRoll>
    <blogChannel:blink>http://www.dotnetblogengine.net/syndication.axd</blogChannel:blink>
    <dc:creator>Rob Bihun</dc:creator>
    <dc:title>Rob Bihun</dc:title>
    <geo:lat>33.397390</geo:lat>
    <geo:long>-86.773640</geo:long>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/RobBihunBlog" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
      <title>ASP.NET Uploading and Resizing Images</title>
      <description>&lt;p&gt;When working on the web whether it be a full blown CMS or a small product cart. The issue of how to upload images, and especially resize them to fit your site comes up quite a bit. C# has a useful image library that you can use to resize your images to fit your needs. This post will show you how to upload the file, manipulate it, and then save it so that it can be used where you need it.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;For this post we are going to make a *very* simple image gallery. Our image gallery will only have one “default” album and display the thumbnails of all of the images. In a later post I will implement the functionality to view larger sizes of the images (using some pretty cool JQuery plugins).&lt;/p&gt;  &lt;h4&gt;The Spec:&lt;/h4&gt;  &lt;p&gt;We want to upload images and resize them to 2 different sizes, Thumbnails and the large size image. We do not want to store the images themselves in a database; we do however, want to persist the image location into the database. And finally we need a page to display all the thumbnails and link to the full size images.&lt;/p&gt;  &lt;h4&gt;Step One:&lt;/h4&gt;  &lt;p&gt;First we are going to create our data structure to hold our images and other data. In the database we are going to create a table with 4 columns.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://robbihun.com/image.axd?picture=Blog_Post_Image_Gallery_DB_Schema.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Blog_Post_Image_Gallery_DB_Schema" border="0" alt="Blog_Post_Image_Gallery_DB_Schema" src="http://robbihun.com/image.axd?picture=Blog_Post_Image_Gallery_DB_Schema_thumb.png" width="244" height="75" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We will be storing the image title and relative web paths to the thumbnail and the full size image here. We also need to create our directory structure where the files will actually be stored in our web root. Here we are storing our images in the &amp;quot;UserImages” folder and subfolders.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://robbihun.com/image.axd?picture=Blog_Post_Image_Gallery_File_Structure.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Blog_Post_Image_Gallery_File_Structure" border="0" alt="Blog_Post_Image_Gallery_File_Structure" src="http://robbihun.com/image.axd?picture=Blog_Post_Image_Gallery_File_Structure_thumb.png" width="232" height="221" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h4&gt;Step Two:&lt;/h4&gt;  &lt;p&gt;We need to create a page where we will upload our files.&amp;#160; Right Click on your web project and add a new aspx page. You will need to add a file upload control and text boxes for all of the properties you would like to store in the database (in our case, just the Title).&lt;/p&gt;  &lt;pre class="brush: xml;"&gt;    &amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;
    &amp;lt;div class=&amp;quot;field&amp;quot;&amp;gt;
        &amp;lt;asp:Label ID=&amp;quot;ImageTitle&amp;quot; runat=&amp;quot;server&amp;quot; AssociatedControlID=&amp;quot;ImageTitleText&amp;quot;&amp;gt;Image Title:&amp;lt;/asp:Label&amp;gt;
        &amp;lt;asp:TextBox ID=&amp;quot;ImageTitleText&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class=&amp;quot;field&amp;quot;&amp;gt;
        &amp;lt;asp:Label ID=&amp;quot;ImageValue&amp;quot; runat=&amp;quot;server&amp;quot; AssociatedControlID=&amp;quot;ImageValueFile&amp;quot;&amp;gt;Image:&amp;lt;/asp:Label&amp;gt;
        &amp;lt;asp:FileUpload ID=&amp;quot;ImageValueFile&amp;quot; runat=&amp;quot;server&amp;quot; /&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class=&amp;quot;buttons&amp;quot;&amp;gt;
        &amp;lt;asp:Button ID=&amp;quot;Submit&amp;quot; runat=&amp;quot;server&amp;quot; Text=&amp;quot;Save Image&amp;quot; OnClick=&amp;quot;SaveImage_Click&amp;quot; /&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;/form&amp;gt;&lt;/pre&gt;

&lt;p&gt;If you are doing this in a production environment you would want to secure this page somehow. For our purposes we are just going to leave the page unsecure. Also, notice that we only have one file upload control on the page. We don’t want to have to resize each of our images ourselves in Photoshop, or worse wait for someone else to do it. We are going to have our website do it for us.&lt;/p&gt;

&lt;h4&gt;Step Three:&lt;/h4&gt;

&lt;p&gt;Here is where we get to the meat of this post. We need to decide what size of images we want. For our purpose we want to keep the aspect ratio of the images as they are uploaded. We do not want to crop them to “all be square images.” So we are going to resize our images to have a max thumbnail size of 150 x 150 and a max large size of 500 x 500 (just in case anyone tries to upload a file straight from their digital SLR). Here is our button click event&lt;/p&gt;

&lt;pre class="brush: csharp; collapse: true;"&gt;        protected void SaveImage_Click(object sender, EventArgs e)
        {
            // First check if there is a file present.
            // Should also check that the file is an allowed type.
            if (ImageValueFile.HasFile)
            {
                // We have a file. Save the image
                if (SaveImage(ImageValueFile.PostedFile, ImageTitleText.Text))
                    Response.Write(&amp;quot;Your Image Has Been Saved&amp;quot;);
                else
                    Response.Write(&amp;quot;There was an error in saving your image.&amp;quot;);

            }&lt;/pre&gt;

&lt;p&gt;And the SaveImage function that it calls&lt;/p&gt;

&lt;pre class="brush: csharp; collapse: true; highlight: [18, 19, 20];"&gt;        public bool SaveImage(HttpPostedFile image, string title)
        {
            bool result = false;
            int MaxWidth = 500;
            int MaxHeight = 500;
            int ThumbMaxWidth = 150;
            int ThumbMaxHeight = 150;

            // Ensure a unique filename
            string upFileName = new Guid().ToString() + image.FileName.Substring(image.FileName.LastIndexOf(&amp;quot;.&amp;quot;));

            // Should put this into a config file.
            string LargeFile = @&amp;quot;UserImages\Large\&amp;quot; + upFileName;
            string ThumbFile = @&amp;quot;UserImages\Thumbs\&amp;quot; + upFileName;

            try
            {
                System.Drawing.Image UploadedImage = System.Drawing.Image.FromStream(image.InputStream);
                System.Drawing.Image LargeImage = ImageTool.ToMaxSize(UploadedImage, MaxWidth, MaxHeight);
                System.Drawing.Image ThumbImage = ImageTool.ToMaxSize(UploadedImage, ThumbMaxWidth, ThumbMaxHeight);

                LargeImage.Save(Request.PhysicalApplicationPath + LargeFile);
                ThumbImage.Save(Request.PhysicalApplicationPath + ThumbFile);
            }
            catch (Exception ex)
            {
                return false;
            }

            GalleryDataContext db = new GalleryDataContext();

            // Save the image paths and title to the database using LINQ
            GalleryImage i = new GalleryImage();
            i.FullSize = LargeFile.Replace('\\', '/');
            i.Thumbnail = ThumbFile.Replace('\\', '/');

            i.Title = title;

            try
            {
                db.GalleryImages.InsertOnSubmit(i);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                return false;
            }

            return result;
        }&lt;/pre&gt;

&lt;p&gt;The only real thing this function does is convert the posted file into a System.Drawing.Image and then call a utility class that will do the actual resizing ( lines 18 - 20 ). Everything after that is just a LINQ expression to insert the paths to the database. The function ImageTool.ToMaxSize is as follows:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;        public static Image ToMaxSize(Image image, int maxWidth, int maxHeight)
        {
            int newWidth = 0;
            int newHeight = 0;
            int currentWidth = image.Width;
            int currentHeight = image.Height;

            if ((currentWidth / (double)maxWidth) &amp;gt; (currentHeight / (double)maxHeight))
            {
                newWidth = maxWidth;
                newHeight = Convert.ToInt32(currentHeight * (maxWidth / (double)currentWidth));
                if (newHeight &amp;gt; maxHeight)
                {
                    newWidth = Convert.ToInt32(maxWidth * (maxHeight / (double)newHeight));
                    newHeight = maxHeight;
                }
            }
            else
            {
                newWidth = Convert.ToInt32(currentWidth * (maxHeight / (double)currentHeight));
                newHeight = maxHeight;
                if (newWidth &amp;gt; maxWidth)
                {
                    newWidth = maxWidth;
                    newHeight = Convert.ToInt32(maxHeight * (maxWidth / (double)newWidth));
                }
            }

            Bitmap newImage = new Bitmap(newWidth, newHeight);
            newImage.SetResolution(72, 72); //web resolution;

            //create a graphics object 
            Graphics gr = Graphics.FromImage(newImage);

            //just in case it's a transparent GIF force the bg to white 
            SolidBrush sb = new SolidBrush(System.Drawing.Color.White);
            gr.FillRectangle(sb, 0, 0, newImage.Width, newImage.Height);

            //Re-draw the image to the specified height and width
            gr.DrawImage(image, 0, 0, newImage.Width, newImage.Height);

            return newImage;
        }&lt;/pre&gt;

&lt;p&gt;Here we are doing some math to see which is larger, the width or the height. It will scale the image down by the largest value to get the original smaller value “within the range” that we want. Then we create a new Bitmap object with our new width and height. Finally we use the .NET graphics library to paint our canvas white and scale our uploaded image into that newly painted canvas.&lt;/p&gt;

&lt;h4&gt;Final Step:&lt;/h4&gt;

&lt;p&gt;At this point we have the images saved to our web server and the relative paths stored in the database. Now all we need is a page to display the thumbnails. I will show this in my next post where I will also display the images using some JQuery plugins. I will post all my code at the end of the next post.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/k-TJ7kMOtPdc2k2-8irQHvMxACY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/k-TJ7kMOtPdc2k2-8irQHvMxACY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/k-TJ7kMOtPdc2k2-8irQHvMxACY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/k-TJ7kMOtPdc2k2-8irQHvMxACY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RobBihunBlog/~4/FRZICvFwHiU" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RobBihunBlog/~3/FRZICvFwHiU/post.aspx</link>
      <author>robbihun</author>
      <comments>http://blog.robbihun.com/post/2009/10/11/ASPNET-Uploading-and-Resizing-Images.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.robbihun.com/post.aspx?id=034de5d6-4303-469e-bf93-a737350c5d9d</guid>
      <pubDate>Sun, 11 Oct 2009 11:45:00 -0600</pubDate>
      <category>ASP.NET</category>
      <category>SQL Server</category>
      <category>General</category>
      <category>LINQ</category>
      <dc:publisher>robbihun</dc:publisher>
      <pingback:server>http://blog.robbihun.com/pingback.axd</pingback:server>
      <pingback:target>http://blog.robbihun.com/post.aspx?id=034de5d6-4303-469e-bf93-a737350c5d9d</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.robbihun.com/trackback.axd?id=034de5d6-4303-469e-bf93-a737350c5d9d</trackback:ping>
      <wfw:comment>http://blog.robbihun.com/post/2009/10/11/ASPNET-Uploading-and-Resizing-Images.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.robbihun.com/syndication.axd?post=034de5d6-4303-469e-bf93-a737350c5d9d</wfw:commentRss>
    <feedburner:origLink>http://blog.robbihun.com/post.aspx?id=034de5d6-4303-469e-bf93-a737350c5d9d</feedburner:origLink></item>
    <item>
      <title>Generate a Custom Password using SQLMembership Provider</title>
      <description>&lt;p&gt;We use SQLMembership provider a lot; however, we always add custom logic and extended fields in the database for the user (relating the login in the membership provider to our tables). Recently we had a request that the client wanted to &amp;quot;reset&amp;quot; their user's passwords and give be able to tell them their new password verbally. &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;To the page where they edit their users, i added some logic and a button for them to &amp;quot;Reset Password&amp;quot; which called the MembershipUser.ResetPassword() method.&lt;/p&gt;  &lt;p&gt;This worked but it generated something like &lt;strong&gt;qS2xh&amp;amp;^23dtg &lt;/strong&gt;as the password. They wanted this to be shorter and easier to remember (as a temporary password). This was easy, and gave me the chance to do something creative for once.&lt;/p&gt;  &lt;p&gt;We decided to generate two random words and concatenate them for the new password. Since we are use the SQLMembershipProvider and not our own we had to override the GeneratePassword() function and place our logic in there.&lt;/p&gt;  &lt;p&gt;First, I created a new class called ExtSQLMembershipProvider&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;    public class ExtMembershipProvider : System.Web.Security.SqlMembershipProvider
    {
        public ExtMembershipProvider()
            : base()
        {

        }

        public override string GeneratePassword()
        {
            AppDataContext db = new AppDataContext();

            var words = db.Words.GetRandom(2).ToArray();

            return words[0].Word + words[1].Word;
        }
    }&lt;/pre&gt;

&lt;p&gt;You will notice I'm creating a call via LINQ to get two random words from the database and returning the first and second word. That is it... well, I did have to create the GetRandom extension method, but it was trivial – here is the code for that.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;    public static class Extenders
    {
        public static IEnumerable&amp;lt;T&amp;gt; GetRandom&amp;lt;T&amp;gt;(this IEnumerable&amp;lt;T&amp;gt; target, int count)
        {
            Random r = new Random();
            for (int i = 0; i &amp;lt; count; i++)
            {
                int position = r.Next(target.Count&amp;lt;T&amp;gt;());
                yield return target.ElementAt&amp;lt;T&amp;gt;(position);
            }
        }
    }&lt;/pre&gt;

&lt;p&gt;Bam, set up a table with a bunch of random 4 or 5 letter words and you get passwords like &lt;strong&gt;houseball&lt;/strong&gt;, much easier to remember than &lt;strong&gt;qS2xh&amp;amp;^23dtg&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;The only thing that needs to change in the web.config is the membership provider type needs to be set to the assembly of your extended SQLMembershipProvider. In this case we have&lt;/p&gt;

&lt;pre class="brush: xml;"&gt;        &amp;lt;membership  defaultProvider=&amp;quot;sqlProvider&amp;quot;&amp;gt;
            &amp;lt;providers&amp;gt;
                &amp;lt;add name=&amp;quot;sqlProvider&amp;quot; type=&amp;quot;MyNamespace.ExtMembershipProvider&amp;quot; /&amp;gt;
            &amp;lt;/providers&amp;gt;
        &amp;lt;/membership&amp;gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Easy 10 minute solution that made the client ecstatic!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/FOebAoRT8u6pyiXVHIsVZ91HgCc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FOebAoRT8u6pyiXVHIsVZ91HgCc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/FOebAoRT8u6pyiXVHIsVZ91HgCc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FOebAoRT8u6pyiXVHIsVZ91HgCc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RobBihunBlog/~4/jLpmLw3QVuQ" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RobBihunBlog/~3/jLpmLw3QVuQ/post.aspx</link>
      <author>robbihun</author>
      <comments>http://blog.robbihun.com/post/2009/08/26/SQLMembership-Provider-Generate-Custom-Random-Password.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.robbihun.com/post.aspx?id=8585fe5b-7674-4add-b7d8-08a9f3e6388e</guid>
      <pubDate>Wed, 26 Aug 2009 12:02:37 -0600</pubDate>
      <category>LINQ</category>
      <category>ASP.NET</category>
      <dc:publisher>robbihun</dc:publisher>
      <pingback:server>http://blog.robbihun.com/pingback.axd</pingback:server>
      <pingback:target>http://blog.robbihun.com/post.aspx?id=8585fe5b-7674-4add-b7d8-08a9f3e6388e</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.robbihun.com/trackback.axd?id=8585fe5b-7674-4add-b7d8-08a9f3e6388e</trackback:ping>
      <wfw:comment>http://blog.robbihun.com/post/2009/08/26/SQLMembership-Provider-Generate-Custom-Random-Password.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.robbihun.com/syndication.axd?post=8585fe5b-7674-4add-b7d8-08a9f3e6388e</wfw:commentRss>
    <feedburner:origLink>http://blog.robbihun.com/post.aspx?id=8585fe5b-7674-4add-b7d8-08a9f3e6388e</feedburner:origLink></item>
    <item>
      <title>TripleDES Encrypt/Decrypt Extension Methods</title>
      <description>&lt;p&gt;Every developer has reusable utilities that they have created and perfected during their time in development. One of the most favorite ones in my arsenal is a utility to encrypt and decrypt strings using TripleDES encryption. &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Instead of having to look up the System.Security.Cryptography namespace every time I need to encrypt or decrypt a string, which honestly I only use about once every few months, I have converted my &amp;quot;helper&amp;quot; class to use Extension methods. So instead of:&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;string val = &amp;quot;something&amp;quot;;
string encrypted = RobBihun.Tools.Security.TDESEncryption.Encrypt(val);&lt;/pre&gt;

&lt;p&gt;I can have:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;string val = &amp;quot;something&amp;quot;;
string encrypted = val.Encrypt();&lt;/pre&gt;

&lt;p&gt;Of course, you need to import the namespace that contains the extension methods. Also, you should create your own encryption keys instead of using hard-coded defaults. Here is the full code in case you want to use it.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace RobBihun.Tools.ExtensionMethods
{
    public static class StringExtensions
    {
        private static TripleDESCryptoServiceProvider tDesProvider = new TripleDESCryptoServiceProvider();
        private static UTF8Encoding strCoder = new UTF8Encoding();

        //encryption keys to use by default - Best practice would be to use custom keys set at runtime (not hard coded)
        private static byte[] badEncKey = { 1, 3, 77, 5, 5, 98, 7, 55, 9, 10, 3, 12, 5, 15, 15, 36, 17, 28, 19, 20, 8, 22, 88, 24 };
        private static byte[] badEncIv = { 8, 7, 6, 5, 4, 3, 2, 1 };

        public static string Encrypt(this string text)
        {
            //throw new Exception(&amp;quot;You're an idiot&amp;quot;);
            byte[] input = strCoder.GetBytes(text);
            byte[] output = input.Transform(tDesProvider.CreateEncryptor(badEncKey, badEncIv));
            return Convert.ToBase64String(output);
        }

        public static string Decrypt(this string text)
        {
            //throw new Exception(&amp;quot;You're a major idiot&amp;quot;);
            byte[] input = Convert.FromBase64String(text);
            byte[] output = input.Transform(tDesProvider.CreateDecryptor(badEncKey, badEncIv));
            return strCoder.GetString(output);
        }

        public static string Encrypt(this string text, byte[] encKey, byte[] encIv)
        {
            byte[] input = strCoder.GetBytes(text);
            byte[] output = input.Transform(tDesProvider.CreateEncryptor(encKey, encIv));
            return Convert.ToBase64String(output);
        }

        public static string Decrypt(this string text, byte[] encKey, byte[] encIv)
        {
            byte[] input = Convert.FromBase64String(text);
            byte[] output = input.Transform(tDesProvider.CreateDecryptor(encKey, encIv));
            return strCoder.GetString(output);
        }


        private static byte[] Transform(this byte[] input, ICryptoTransform CryptoTransform)
        {
            MemoryStream memStream = new MemoryStream();

            CryptoStream cryStream = new CryptoStream(memStream, CryptoTransform, CryptoStreamMode.Write);
            cryStream.Write(input, 0, input.Length);
            cryStream.FlushFinalBlock();
            memStream.Position = 0;

            byte[] result = memStream.ToArray();

            memStream.Close();
            cryStream.Close();

            return result;
        }
    }
}&lt;/pre&gt;

&lt;p&gt;Of course, if you have any comments or suggestions, please leave them below!&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:22d06159-9b5b-474e-a0cc-b69ae29cbc9a" class="wlWriterEditableSmartContent"&gt;&lt;p&gt;You can &lt;a href="http://blog.robbihun.com/file.axd?file=StringEncryption_1.zip" target="_blank"&gt;Download the Full Sample Here&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/dN4PCMCunAT31ECGF1dbpASOXno/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dN4PCMCunAT31ECGF1dbpASOXno/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/dN4PCMCunAT31ECGF1dbpASOXno/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dN4PCMCunAT31ECGF1dbpASOXno/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RobBihunBlog/~4/ABPii9zaUEk" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RobBihunBlog/~3/ABPii9zaUEk/post.aspx</link>
      <author>robbihun</author>
      <comments>http://blog.robbihun.com/post/2009/08/12/TripleDES-EncryptDecrypt-Extension-Methods.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.robbihun.com/post.aspx?id=5ef96d8b-90d1-44f2-adc0-10f81240ba9a</guid>
      <pubDate>Wed, 12 Aug 2009 18:43:00 -0600</pubDate>
      <category>General</category>
      <dc:publisher>robbihun</dc:publisher>
      <pingback:server>http://blog.robbihun.com/pingback.axd</pingback:server>
      <pingback:target>http://blog.robbihun.com/post.aspx?id=5ef96d8b-90d1-44f2-adc0-10f81240ba9a</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://blog.robbihun.com/trackback.axd?id=5ef96d8b-90d1-44f2-adc0-10f81240ba9a</trackback:ping>
      <wfw:comment>http://blog.robbihun.com/post/2009/08/12/TripleDES-EncryptDecrypt-Extension-Methods.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.robbihun.com/syndication.axd?post=5ef96d8b-90d1-44f2-adc0-10f81240ba9a</wfw:commentRss>
    <feedburner:origLink>http://blog.robbihun.com/post.aspx?id=5ef96d8b-90d1-44f2-adc0-10f81240ba9a</feedburner:origLink></item>
    <item>
      <title>I love the Coalesce operator in C#</title>
      <description>&lt;p&gt;Recently I was given a requirement where clients can enter alternate text for particular content and even alternate text to the alternate text. They wanted it so that the default text would only show if the first and second alternate text was null.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;So basically we have :&lt;/p&gt;  &lt;p&gt;Text, varchar(max)    &lt;br /&gt;AlternateText1, varchar(max)     &lt;br /&gt;AlternateText2, varchar(max)     &lt;br /&gt;    &lt;br /&gt;Try to show &amp;quot;AlternateText2&amp;quot;     &lt;br /&gt;If&amp;#160; &amp;quot;AlternateText2&amp;quot; is null – show &amp;quot;AlternateText1&amp;quot;     &lt;br /&gt;If &amp;quot;AlternateText1&amp;quot; is null – show &amp;quot;Text&amp;quot; &lt;/p&gt;  &lt;p&gt;So what is easier?&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;     
string ItemText = string.Empty;
if (string.IsNullOrEmpty(c.AlternateText2))
{
	if (string.IsNullOrEmpty(c.AlternateText1))
	{
		ItemText = c.Text;
	}
	else
	{
		ItemText = c.AlternateText1;
	}
}
else
{
	ItemText = c.AlternateText2;
}&lt;/pre&gt;

&lt;p&gt;Or.... integrating it into our LINQ Query itself?&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;                                       
from u in something.DefaultIfEmpty()
select new
{
	ID = c.ID,
	ItemText = c.AlternateText2 ?? c.AlternateText1 ?? c.Text ?? &amp;quot;Oops, no text available&amp;quot;,
	ItemDate = c.ItemDate,
	FirstName = u.FirstName,
	LastName = u.LastName,
})&lt;/pre&gt;

&lt;p&gt;That is all, nothing special here – Maybe it is the cold medicine this morning, but I was just really thankful that I did not have to write a lot of code to fulfill a fairly simple requirement.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/z70qAB82l5tI-uwesVinUzSxEco/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/z70qAB82l5tI-uwesVinUzSxEco/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/z70qAB82l5tI-uwesVinUzSxEco/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/z70qAB82l5tI-uwesVinUzSxEco/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RobBihunBlog/~4/lnUNJqJnU0A" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RobBihunBlog/~3/lnUNJqJnU0A/post.aspx</link>
      <author>robbihun</author>
      <comments>http://blog.robbihun.com/post/2009/08/11/I-love-the-Coalesce-operator-in-C.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.robbihun.com/post.aspx?id=64064f51-5861-494f-ab12-ef93d5a3bf7c</guid>
      <pubDate>Tue, 11 Aug 2009 09:47:32 -0600</pubDate>
      <category>.NET 3.5</category>
      <category>LINQ</category>
      <category>General</category>
      <dc:publisher>robbihun</dc:publisher>
      <pingback:server>http://blog.robbihun.com/pingback.axd</pingback:server>
      <pingback:target>http://blog.robbihun.com/post.aspx?id=64064f51-5861-494f-ab12-ef93d5a3bf7c</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://blog.robbihun.com/trackback.axd?id=64064f51-5861-494f-ab12-ef93d5a3bf7c</trackback:ping>
      <wfw:comment>http://blog.robbihun.com/post/2009/08/11/I-love-the-Coalesce-operator-in-C.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.robbihun.com/syndication.axd?post=64064f51-5861-494f-ab12-ef93d5a3bf7c</wfw:commentRss>
    <feedburner:origLink>http://blog.robbihun.com/post.aspx?id=64064f51-5861-494f-ab12-ef93d5a3bf7c</feedburner:origLink></item>
    <item>
      <title>Explaining C# Features in LINQ</title>
      <description>&lt;h4&gt;&amp;#160;&lt;/h4&gt;  &lt;p&gt;I will go into some of the newer features of C# 3.0 specifically those that are involved with LINQ. &lt;/p&gt;  &lt;p&gt;On July 25th and 26th the BSDA will be hosting an event called LINQ Bootcamp where presenters will go through the book “Programming Microsoft LINQ” chapter by chapter (1 – 12).&amp;#160; It will be a fun weekend and a great chance to get your feet wet with LINQ. &lt;/p&gt;  &lt;p&gt;If you don’t think you will be able to make it to the event I would still check out &lt;a href="http://www.amazon.com/gp/product/0735624003/?tag=se04-20" target="_blank"&gt;the book&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.robbihun.com/image.axd?picture=book-300x300_1.jpg"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="book-300x300" border="0" alt="book-300x300" src="http://blog.robbihun.com/image.axd?picture=book-300x300_thumb_1.jpg" width="240" height="240" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;With that said let's dive right in!&lt;/p&gt;  &lt;h4&gt;Implicitly Typed Variables&lt;/h4&gt;  &lt;p&gt;These are just variables declared with the var keyword and assigned a value. Once assigned a value and the type is inferred based on the value it is set to. Once set the type of the variable cannot be changed. Basically the var keyword is another way for you to be lazy - The compiler will do all the work for you to determine what the type of that variable should be and then set it. Once it is set you cannot set it to another type.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Example:&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;            
    var myVariable = 1;
    myVariable = &amp;quot;Test&amp;quot;; // this will not work because you cannot convert (implicitly) a string to an int.&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;Object Initializers&lt;/h4&gt;

&lt;p&gt;This is another shorthand, this is a way of instantiating an object and assign values to it's properties in one step, sort of like is possible with Built-In data types (int, string, bool...)&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;            int indexer = 1;
            string name = &amp;quot;test&amp;quot;;
            bool isActive = true;&lt;/pre&gt;

&lt;p&gt;However, before the appearence of object initializers in C# to create an instance and initialize a custom business object you would need to do something like the following (unless you created several overloaded constructors):&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;            Person person = new Person();
            person.Age = 32;
            person.FirstName = &amp;quot;John&amp;quot;;
            person.LastName = &amp;quot;Doe&amp;quot;;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Using this shortcut you can now initialize a custom object as follows:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;            Person person = new Person
            {
                Age = 32,
                FirstName = &amp;quot;John&amp;quot;,
                LastName = &amp;quot;Doe&amp;quot;
            };&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;Anonymous Types&lt;/h4&gt;

&lt;p&gt;Anonymous types are a shortcut way to create custom objects with read-only properties. The compiler will generate a type name for the anonymous type and infer the properties for that type. Since the object type is not available before compile time the use of Implicitly typed variables and Object Initializers are used here.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;            var person = new 
            { 
                Age = 32, 
                FirstName = &amp;quot;John&amp;quot;, 
                LastName = &amp;quot;Doe&amp;quot; 
            };

            person.Age = 53; // Cannot do this - Read-Only Property.&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;Extension Methods&lt;/h4&gt;

&lt;p&gt;Basically an extension method is a shorthand way of creating a wrapper method. When compiled the extension method is actually called as if it was a wrapper method. Extension methods musts be defined as static, their first parameter must be declared with the this modifier and defines the object type that the method applies to.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;namespace LinqBootcamp
{
    public static class IntExtensions
    {
        public static int Add(this int source, int toAdd)
        {
            return source + toAdd;
        }
    }
}&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Once you have the extension method - you will need to import the namespace containing your extension and then you can use it as follows. In this case&amp;#160; the “Add” method only applies to integers because the first parameter&amp;#160; in the extension method is an integer.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;            int test = 5;
            int a, b;

            a = test.Add(5); // a Equals 10
            b = (10).Add(10); // b Equals 20&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/F5YO2zp4Q0uRkKWi_ASqpqfvdFY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/F5YO2zp4Q0uRkKWi_ASqpqfvdFY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/F5YO2zp4Q0uRkKWi_ASqpqfvdFY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/F5YO2zp4Q0uRkKWi_ASqpqfvdFY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RobBihunBlog/~4/Jszl_fj8y_0" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RobBihunBlog/~3/Jszl_fj8y_0/post.aspx</link>
      <author>robbihun</author>
      <comments>http://blog.robbihun.com/post/2009/07/21/Explaining-C-Features-for-LINQ.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.robbihun.com/post.aspx?id=6170d92e-fc21-49e7-9e22-875ec7937544</guid>
      <pubDate>Tue, 21 Jul 2009 11:31:00 -0600</pubDate>
      <category>LINQ</category>
      <dc:publisher>robbihun</dc:publisher>
      <pingback:server>http://blog.robbihun.com/pingback.axd</pingback:server>
      <pingback:target>http://blog.robbihun.com/post.aspx?id=6170d92e-fc21-49e7-9e22-875ec7937544</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://blog.robbihun.com/trackback.axd?id=6170d92e-fc21-49e7-9e22-875ec7937544</trackback:ping>
      <wfw:comment>http://blog.robbihun.com/post/2009/07/21/Explaining-C-Features-for-LINQ.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.robbihun.com/syndication.axd?post=6170d92e-fc21-49e7-9e22-875ec7937544</wfw:commentRss>
    <feedburner:origLink>http://blog.robbihun.com/post.aspx?id=6170d92e-fc21-49e7-9e22-875ec7937544</feedburner:origLink></item>
    <item>
      <title>ASP.NET 301 Redirect In Master Pages</title>
      <description>&lt;p&gt;Today I was asked if we could set up a 301 Redirect for all non &amp;ldquo;www&amp;rdquo; request. For example if someone requested &lt;a href="http://robbihun.com/page/about-me.aspx"&gt;http://robbihun.com/page/about-me.aspx&lt;/a&gt; it would automatically do a 301 (permanent) redirect to &lt;a href="http://www.robbihun.com/page/about-me.aspx"&gt;http://www.robbihun.com/page/about-me.aspx&lt;/a&gt; thus making all existing links (and SEO links) work without issue.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Basically all you have to do is check the requested url, check for the existance of the www. and if it is not present, set the HTTP Headers to do a 301 redirect to the same page to the www request.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I added the following to the master page &amp;ndash; its not my favorite code ever, but it was quick to write and implement&amp;hellip; and most importantly, works.&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;    protected void Page_Load(object sender, EventArgs e)
    {
        string requestPath = GetApplicationPath().ToLowerInvariant();
        string redirectPath = "~";

        if (!requestPath.Contains("www."))
        {
            if (requestPath.Contains("http://"))
            {
                redirectPath = reqPath.Substring(reqPath.IndexOf('/', 6));
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", "http://www.domain.com" + redirectPath);
            }
            else
            {
                redirectPath = requestPath.Substring(reqPath.IndexOf('/'));
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", "http://www.domain.com" + redirectPath);
            }
        }
    }
    public string GetApplicationPath()
    {
        string applicationPath = "";

        if (this.Page.Request.Url != null)
            applicationPath = this.Page.Request.Url.AbsoluteUri;
        return applicationPath;
    }&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yFvLuhpHvuEZ-pW6wgDoEfc9yAY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yFvLuhpHvuEZ-pW6wgDoEfc9yAY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yFvLuhpHvuEZ-pW6wgDoEfc9yAY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yFvLuhpHvuEZ-pW6wgDoEfc9yAY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RobBihunBlog/~4/7G3Vh0RxkAM" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RobBihunBlog/~3/7G3Vh0RxkAM/post.aspx</link>
      <author>robbihun</author>
      <comments>http://blog.robbihun.com/post/2009/06/18/ASPNET-301-Redirect-In-Master-Pages.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.robbihun.com/post.aspx?id=b45210c3-a08e-49a0-bb2a-ef0feb82a564</guid>
      <pubDate>Thu, 18 Jun 2009 11:24:00 -0600</pubDate>
      <category>ASP.NET</category>
      <category>General</category>
      <dc:publisher>robbihun</dc:publisher>
      <pingback:server>http://blog.robbihun.com/pingback.axd</pingback:server>
      <pingback:target>http://blog.robbihun.com/post.aspx?id=b45210c3-a08e-49a0-bb2a-ef0feb82a564</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.robbihun.com/trackback.axd?id=b45210c3-a08e-49a0-bb2a-ef0feb82a564</trackback:ping>
      <wfw:comment>http://blog.robbihun.com/post/2009/06/18/ASPNET-301-Redirect-In-Master-Pages.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.robbihun.com/syndication.axd?post=b45210c3-a08e-49a0-bb2a-ef0feb82a564</wfw:commentRss>
    <feedburner:origLink>http://blog.robbihun.com/post.aspx?id=b45210c3-a08e-49a0-bb2a-ef0feb82a564</feedburner:origLink></item>
    <item>
      <title>Manipulating POST Data with Fiddler</title>
      <description>&lt;p&gt;I like it when a new programming challenge crosses my mind. This is something i've never done before and it was a fun, quick challenge.&lt;/p&gt;
&lt;p&gt;It all started with a &lt;a href="http://twitter.com/atcrawford/status/2080194402"&gt;simple twitter post&lt;/a&gt;&amp;nbsp;that said&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;So who's writing the scipt to automatically put &lt;br /&gt; #squarespace into every tweet for the next 30 days?&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Since I use &lt;a href="http://www.thirteen23.com/experiences/desktop/blu/"&gt;blu&lt;/a&gt; as my twitter client of choice (for now), my mind went immediately to how to manipulate the post to the server. I pulled up &lt;a href="http://www.fiddler2.com/fiddler2/"&gt;fiddler&lt;/a&gt;, a web debugging proxy to view and minipulate request and response data.&lt;/p&gt;
&lt;p&gt;I made a post via blu while fiddler was running and looked for the request data.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blog.robbihun.com/image.axd?picture=2009%2f6%2fpost.JPG" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I then checked the raw post to see how it was posting it to the server - in this case it was a simple HTTP POST. NOTE: this example image is after my modification.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blog.robbihun.com/image.axd?picture=2009%2f6%2fdata2.JPG" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A little poking around and I found that you could manipulate the body and then send the manipulated version. Even programatically&lt;/p&gt;
&lt;p&gt;I opened up my CustomRules.js by going to Rules -&amp;gt; Customize Rules and modified the OnbeforeRequest method and added:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre class="brush: xml;"&gt;		// intercept blu twitter posts and append data.
		if (oSession.HTTPMethodIs("POST") &amp;amp;&amp;amp; (oSession.HostnameIs("twitter.com") || oSession.HostnameIs("www.twitter.com"))){
			
			var oBody = System.Text.Encoding.UTF8.GetString(oSession.requestBodyBytes);
			
			oBody = oBody.replace("&amp;amp;source", Uri.EscapeDataString( " #squarespace") + "&amp;amp;source");
			
			oSession.utilSetRequestBody(oBody);
		}
&lt;/pre&gt;
&lt;p&gt;Basically, i'm being really cheap here and doing a simple replace.&lt;/p&gt;
&lt;p&gt;Line 4: Capturing the body&lt;br /&gt;Line 6: Replacing &amp;amp;source (which is consistant) with a URI Properly Escaped string containing " #squarespace" and then the original &amp;amp;source parameter.&lt;br /&gt;Line 8: Replacing the original body with the manipulated body.&lt;/p&gt;
&lt;p&gt;Please Note, I know I am not checking the length of the string to make sure i'm within 140 characters; however, I don't care to use this, I just wanted to know if I could do it. This could easily be extended to check the length and only append if there is room. Let me know what you think via &lt;a href="http://www.twitter.com/rbihun"&gt;twitter&lt;/a&gt; or the comments below &amp;nbsp;- or post any enhancements you have to this little snippet!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BlaMj3jPCYUYkyIHuudpibSLtYY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BlaMj3jPCYUYkyIHuudpibSLtYY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BlaMj3jPCYUYkyIHuudpibSLtYY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BlaMj3jPCYUYkyIHuudpibSLtYY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RobBihunBlog/~4/mcU9RBeqOM0" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RobBihunBlog/~3/mcU9RBeqOM0/post.aspx</link>
      <author>robbihun</author>
      <comments>http://blog.robbihun.com/post/2009/06/08/Manipulating-POST-Data-with-Fiddler.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.robbihun.com/post.aspx?id=0d008789-9ec1-4802-8346-8601f0f2b51e</guid>
      <pubDate>Mon, 08 Jun 2009 15:53:00 -0600</pubDate>
      <category>General</category>
      <dc:publisher>robbihun</dc:publisher>
      <pingback:server>http://blog.robbihun.com/pingback.axd</pingback:server>
      <pingback:target>http://blog.robbihun.com/post.aspx?id=0d008789-9ec1-4802-8346-8601f0f2b51e</pingback:target>
      <slash:comments>3</slash:comments>
      <trackback:ping>http://blog.robbihun.com/trackback.axd?id=0d008789-9ec1-4802-8346-8601f0f2b51e</trackback:ping>
      <wfw:comment>http://blog.robbihun.com/post/2009/06/08/Manipulating-POST-Data-with-Fiddler.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.robbihun.com/syndication.axd?post=0d008789-9ec1-4802-8346-8601f0f2b51e</wfw:commentRss>
    <feedburner:origLink>http://blog.robbihun.com/post.aspx?id=0d008789-9ec1-4802-8346-8601f0f2b51e</feedburner:origLink></item>
    <item>
      <title>JQuery Validation with ASP.NET MasterPages</title>
      <description>&lt;p&gt;I love using the jquery &lt;a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" target="_blank"&gt;validation plugin&lt;/a&gt; in my .NET projects; however, there are some things to keep in mind when using it – especially when used in conjunction with master pages.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;h3&gt;What is that field ID?&lt;/h3&gt;  &lt;p&gt;We all know that master pages and content pages generate specific IDs for the form elements to ensure a truly unique ID Value. When using&amp;#160; jQuery validate, you may be tempted to call the fields client id value from .NET as shown below.&lt;/p&gt;  &lt;pre class="brush: xml;"&gt;$(&amp;quot;#aspnetForm&amp;quot;).validate({
	rules: {
		&amp;lt;%=txtName.ClientID%&amp;gt;: {
			required: true
		}
	}
	messages: {
		&amp;lt;%=txtName.ClientID%&amp;gt;: &amp;quot;Please enter your name.&amp;quot;
	}
});&lt;/pre&gt;

&lt;p&gt;Trying to run this example will not work, that is because the validate plugin uses the &amp;quot;name” field of&amp;#160; form elements to run it’s validation. Rewriting the javascript to use UniqueID&amp;#160; instead would work.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;$(&amp;quot;#aspnetForm&amp;quot;).validate({
	rules: {
		&amp;lt;%=txtName.UniqueID%&amp;gt;: {
			required: true
		}
	}
	messages: {
		&amp;lt;%=txtName.UniqueID%&amp;gt;: &amp;quot;Please enter your name.&amp;quot;
	}
});&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/RhTR30vtrxnJ5J_SleM9g_01u0A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/RhTR30vtrxnJ5J_SleM9g_01u0A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/RhTR30vtrxnJ5J_SleM9g_01u0A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/RhTR30vtrxnJ5J_SleM9g_01u0A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RobBihunBlog/~4/idLpmAyIvnU" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RobBihunBlog/~3/idLpmAyIvnU/post.aspx</link>
      <author>robbihun</author>
      <comments>http://blog.robbihun.com/post/2009/05/19/JQuery-Validation-with-ASPNET-MasterPages.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.robbihun.com/post.aspx?id=5161e137-b859-4915-a4c7-0e292802518d</guid>
      <pubDate>Tue, 19 May 2009 15:36:21 -0600</pubDate>
      <category>ASP.NET</category>
      <category>jQuery</category>
      <category>General</category>
      <dc:publisher>robbihun</dc:publisher>
      <pingback:server>http://blog.robbihun.com/pingback.axd</pingback:server>
      <pingback:target>http://blog.robbihun.com/post.aspx?id=5161e137-b859-4915-a4c7-0e292802518d</pingback:target>
      <slash:comments>3</slash:comments>
      <trackback:ping>http://blog.robbihun.com/trackback.axd?id=5161e137-b859-4915-a4c7-0e292802518d</trackback:ping>
      <wfw:comment>http://blog.robbihun.com/post/2009/05/19/JQuery-Validation-with-ASPNET-MasterPages.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.robbihun.com/syndication.axd?post=5161e137-b859-4915-a4c7-0e292802518d</wfw:commentRss>
    <feedburner:origLink>http://blog.robbihun.com/post.aspx?id=5161e137-b859-4915-a4c7-0e292802518d</feedburner:origLink></item>
    <item>
      <title>My favorite JQuery Plugins to use with ASP.NET</title>
      <description>&lt;p&gt;If&amp;#160; you ran across this, you are probably familiar with JQuery and are more than likely a Microsoft .NET Developer. Below you will find some of my favorite and most useful plugins that are easy to use / implement in an ASP.NET site. Note these plugins are not designed specifically for use with .NET they are just the ones I find extremely useful.&lt;/p&gt;  &lt;p&gt;Please leave any comments 0n jquery plugins that you find useful!&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;h2&gt;&lt;/h2&gt;  &lt;h3&gt;JQuery UI&lt;/h3&gt;  &lt;p&gt;Okay, so it is not exactly &lt;em&gt;a&lt;/em&gt; plugin, more a set of plugins; however, I find many useful things in the UI library. Specifically Tabs, Sortable, and DatePicker are the ones i use the most. Date picker is clean and functional – not to mention it is easier to implement than the ASP.NET AJAX DatePicker.&lt;/p&gt;  &lt;p&gt;Website: &lt;a href="http://jqueryui.com" target="_blank"&gt;http://jqueryui.com&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;jTemplates&lt;/h3&gt;  &lt;p&gt;This one is very useful if you are making AJAX calls to retrieve tables of data (see&amp;#160; my post on &lt;a href="http://blog.robbihun.com/post/2008/10/23/An-Introduction-to-jQuery-and-NET-Web-Services.aspx#continue"&gt;retrieving data from .NET Web Services&lt;/a&gt;). Instead of generating your html in your javascript where it is hard to read and definitely hard to update and maintain you can generate a simple HTML template to format your JSON&amp;#160; data. For&amp;#160; more details and examples using&amp;#160; jTemplates check out their &lt;a href="http://plugins.jquery.com/project/jTemplates" target="_blank"&gt;plugin page&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Website: &lt;a href="http://plugins.jquery.com/project/jTemplates" target="_blank"&gt;http://plugins.jquery.com/project/jTemplates&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Validation&lt;/h3&gt;  &lt;p&gt;You should always perform validation at the server level; however, it does wonders to be able to tell a user of your site that they did not fill out a form properly without doing a postback. Yes, I know you can use asp validators such as requiredfieldvalidator but I feel that every time I take that route, I end up writing a ton of markup just to make sure a field is not empty. This is where the jQuery validation plugin comes into play it has features to check for dates, credit cards, emails and more!&amp;#160; It even makes it really easy to attach your own validation. There are some &lt;a href="http://blog.robbihun.com/post/2009/05/19/JQuery-Validation-with-ASPNET-MasterPages.aspx" target="_blank"&gt;tips and tricks&lt;/a&gt; you should know about when using validation with ASP.NET especially in master pages.&lt;/p&gt;  &lt;p&gt;Website: &lt;a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" target="_blank"&gt;http://bassistance.de/jquery-plugins/jquery-plugin-validation/&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Masked Input&lt;/h3&gt;  &lt;p&gt;This is a simple yet very useful plugin. Ever want to limit a textbox to numbers only or specify a format for the input? Well masked input makes it easy check out &lt;a href="http://digitalbush.com/projects/masked-input-plugin/" target="_blank"&gt;their site&lt;/a&gt; for demos.&lt;/p&gt;  &lt;p&gt;Website: &lt;a href="http://digitalbush.com/projects/masked-input-plugin/" target="_blank"&gt;http://digitalbush.com/projects/masked-input-plugin/&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;QuickSearch&lt;/h3&gt;  &lt;p&gt;This plugin allows you to search text in a DOM element such as an ordered/unordered list or a table. This is one I haven't played with too much. I’m not sure how efficient it is with different sizes of datasets, though I suspect it gets slower with large amounts of data. To use it you just attach it to a table or list element and it will filter your data as you type.&lt;/p&gt;  &lt;p&gt;Website:&amp;#160; &lt;a href="http://rikrikrik.com/jquery/quicksearch/" target="_blank"&gt;http://rikrikrik.com/jquery/quicksearch/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_mqe0U1Aa92qqyjURTOx_-5fXgk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_mqe0U1Aa92qqyjURTOx_-5fXgk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_mqe0U1Aa92qqyjURTOx_-5fXgk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_mqe0U1Aa92qqyjURTOx_-5fXgk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RobBihunBlog/~4/0kOosWXgf7M" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RobBihunBlog/~3/0kOosWXgf7M/post.aspx</link>
      <author>robbihun</author>
      <comments>http://blog.robbihun.com/post/2009/05/19/My-favorite-JQuery-Plugins-to-use-with-ASPNET.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.robbihun.com/post.aspx?id=11144c84-39f8-42ba-9f5a-bf1e7012764c</guid>
      <pubDate>Tue, 19 May 2009 15:29:00 -0600</pubDate>
      <category>ASP.NET</category>
      <dc:publisher>robbihun</dc:publisher>
      <pingback:server>http://blog.robbihun.com/pingback.axd</pingback:server>
      <pingback:target>http://blog.robbihun.com/post.aspx?id=11144c84-39f8-42ba-9f5a-bf1e7012764c</pingback:target>
      <slash:comments>3</slash:comments>
      <trackback:ping>http://blog.robbihun.com/trackback.axd?id=11144c84-39f8-42ba-9f5a-bf1e7012764c</trackback:ping>
      <wfw:comment>http://blog.robbihun.com/post/2009/05/19/My-favorite-JQuery-Plugins-to-use-with-ASPNET.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.robbihun.com/syndication.axd?post=11144c84-39f8-42ba-9f5a-bf1e7012764c</wfw:commentRss>
    <feedburner:origLink>http://blog.robbihun.com/post.aspx?id=11144c84-39f8-42ba-9f5a-bf1e7012764c</feedburner:origLink></item>
    <item>
      <title>Manipulating and Saving Images Locally from a Remote Server</title>
      <description>&lt;p&gt;It has come up a few times. Say you want to be able to allow someone to edit content using a rich text editor and allow them to upload images. Well, often you will find that they are linking images from other servers and the images are not formatted or sized appropriately for your application.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Here is a working example of a simple call to get an image from a remote server using a WebRequest, Manipulating the image and saving it to your server. Be warned that legal issues may arise if you do not have rights to use the image on your site.&lt;/p&gt;
&lt;p&gt;For this example, I am using a picture of my dog found at my main site.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://robbihun.com/image.axd?picture=2009%2f6%2fbeau.jpg" alt="" width="88" height="93" /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To keep this example simple, I am not manipulating or resizing the image.&amp;nbsp; This would be easy to extend to use with a rich text editor. Enjoy!&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;    protected void Page_Load(object sender, EventArgs e)
    {
        string url = "http://www.robbihun.com/images/albums/fs_128664251554700000eau.jpg";
        System.Drawing.Image img = null;

        try
        {
            img = GetImageByURL(url);
            if (img != null)
            {
                //resize the image
                
                //save it to the filesystem.
                string filename = "Beau" + url.Substring(url.LastIndexOf("."));
                img.Save(Server.MapPath("~\\images\\" + filename));
            }
        }
        catch
        {
            lblErrorMessage.Text = "There was an error retrieving your file.";
        }
    }
    private static System.Drawing.Image GetImageByURL(string url)
    {
        WebResponse response = null;
        Stream serverStream = null;
        System.Drawing.Image result = null;

        try
        {
            WebRequest request = WebRequest.Create(url);
            if (request != null)
            {
                response = request.GetResponse();
                if (response != null)
                {
                    serverStream = response.GetResponseStream();
                    return System.Drawing.Image.FromStream(serverStream);
                }
            }
        }
        catch (Exception ex)
        {
            throw;
        }
        finally
        {
            if (response != null) response.Close();
            if (serverStream != null) serverStream.Close();
        }
        return result;
    }&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/WVpdScjyeBGvQi6RuNSEdJaBSxg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WVpdScjyeBGvQi6RuNSEdJaBSxg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/WVpdScjyeBGvQi6RuNSEdJaBSxg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WVpdScjyeBGvQi6RuNSEdJaBSxg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RobBihunBlog/~4/tFFZzayeHt0" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RobBihunBlog/~3/tFFZzayeHt0/post.aspx</link>
      <author>robbihun</author>
      <comments>http://blog.robbihun.com/post/2009/04/15/Manipulating-and-Saving-Images-Locally-from-a-Remote-Server.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.robbihun.com/post.aspx?id=935989fb-bd52-48aa-b398-a46aafd0918d</guid>
      <pubDate>Wed, 15 Apr 2009 14:46:00 -0600</pubDate>
      <category>ASP.NET</category>
      <category>.NET 2.0</category>
      <category>.NET 3.5</category>
      <dc:publisher>robbihun</dc:publisher>
      <pingback:server>http://blog.robbihun.com/pingback.axd</pingback:server>
      <pingback:target>http://blog.robbihun.com/post.aspx?id=935989fb-bd52-48aa-b398-a46aafd0918d</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.robbihun.com/trackback.axd?id=935989fb-bd52-48aa-b398-a46aafd0918d</trackback:ping>
      <wfw:comment>http://blog.robbihun.com/post/2009/04/15/Manipulating-and-Saving-Images-Locally-from-a-Remote-Server.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.robbihun.com/syndication.axd?post=935989fb-bd52-48aa-b398-a46aafd0918d</wfw:commentRss>
    <feedburner:origLink>http://blog.robbihun.com/post.aspx?id=935989fb-bd52-48aa-b398-a46aafd0918d</feedburner:origLink></item>
  </channel>
</rss>
