<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
  <title>Jim Zimmerman - ASP.NET, MVC, Ajax and ORM</title>
  <link rel="alternate" type="text/html" href="http://www.jimzimmerman.com/blog/" />
  <link rel="self" href="http://www.jimzimmerman.com/blog/SyndicationService.asmx/GetAtom" />
  <icon>favicon.ico</icon>
  <updated>2010-03-16T02:37:01.0786250-04:00</updated>
  <author>
    <name>Jim Zimmerman</name>
  </author>
  <subtitle>Web Development Jornal</subtitle>
  <id>http://www.jimzimmerman.com/blog/</id>
  <generator uri="http://www.dasblog.net" version="1.9.6264.0">DasBlog</generator>
  <entry>
    <title>Deploying an Azure Project using TFS 2010</title>
    <link rel="alternate" type="text/html" href="http://www.jimzimmerman.com/blog/2010/03/16/Deploying+An+Azure+Project+Using+TFS+2010.aspx" />
    <id>http://www.jimzimmerman.com/blog/PermaLink,guid,d2f2d519-f49d-4f05-80b8-132279151859.aspx</id>
    <published>2010-03-16T02:32:30.2810000-04:00</published>
    <updated>2010-03-16T02:37:01.0786250-04:00</updated>
    <category term="Azure" label="Azure" scheme="http://www.jimzimmerman.com/blog/CategoryView,category,Azure.aspx" />
    <category term="TFS" label="TFS" scheme="http://www.jimzimmerman.com/blog/CategoryView,category,TFS.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
For those few of you left that read my blog, you are probably wondering if I just
quit writing.  Well I have been super busy creating Facebook apps that run in
Azure.  And these kind of marketing apps that we are doing have marketing deadlines,
which are hard to budge.  So that means many late nights and not much time left
to write.  I am writing this on the plane now on the way to MIX 2010 where I
am speaking on this topic.  I am very excited to be able to speak at MIX. 
I am also tired since i am leaving SXSW.  Awesome conference by the way! 
Anyway on with the post. :)
</p>
        <p>
So, one of the biggest pains in any development is deployment.  And when it comes
to Azure, it is easy to deploy, but still is a very manual process.  Also you
need to deploy from your local Visual Studio which can be very problematic. 
For instance, lets say you publish your package locally, deploy to staging only to
find out that another developer had just checked in a fix and you forgot to get latest
before you deployed.  Well since it can take sometimes 15 minutes to deploy to
staging because of firing up multiple instances, this can become very painful to have
to deploy again right after you just did because of one simple css change or any other
change.
</p>
        <p>
So after going through this pain more than once, actually more like 30+ times, I got
off of my butt and figured out how to deploy to azure from TFS 2010.  This was
a lot of work actually to get to work.  First thing you have to be able to do
is build the cloud project on the server. After trying to change the registry, etc
to get the Azure targets file to work, I decided just to install visual studio 2010
on the server along with the Azure SDK.  This is the only way I knew that it
would actually build.  
</p>
        <p>
So compiling the solution on the server is the first step.  The second step is
to actually package the solution so that is can be deployed to Azure.  You have
to do this by command line using cspack.  This was also a little tricky as I
had to figure out where the path was for the web and worker roles for the cspack to
know what to package.  Basically there is a folder called ProjectName.csx where
your compiled app is placed when it is built.  Here is the entire package script
that is invoked in the TfsBuild.proj file.  
</p>
        <div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper">
          <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 600px; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;" id="codeSnippet">&lt;PackageCommand&gt; 
<br /><span style="color: rgb(0, 96, 128);">"C:\Program Files\Windows Azure SDK\v1.1\bin\cspack"</span><span style="color: rgb(0, 96, 128);">"C:\Builds\1\AzureFacebook\AzureFacebookAzureDeploy\Binaries\Release\AzureFacebook.Cloud.csx\ServiceDefinition.csdef"</span><br /><br />
/role:AzureFacebook.Web;<span style="color: rgb(0, 96, 128);">"C:\Builds\1\AzureFacebook\AzureFacebookAzureDeploy\Binaries\Release\AzureFacebook.Cloud.csx\roles\AzureFacebook.Web\approot"</span>;<br /><br />
AzureFacebook.Web.dll /role:AzureFacebook.WorkerRole;<span style="color: rgb(0, 96, 128);">"C:\Builds\1\AzureFacebook\AzureFacebookAzureDeploy\Binaries\Release\AzureFacebook.Cloud.csx\roles\AzureFacebook.WorkerRole\approot"</span>;<br /><br />
AzureFacebook.WorkerRole.dll /<span style="color: rgb(0, 0, 255);">out</span>:<span style="color: rgb(0, 96, 128);">"C:\Builds\1\AzureFacebook\AzureFacebookAzureDeploy\Binaries\Release\AzureFacebook.cspkg"</span><br />
&lt;/PackageCommand&gt; 
<br /><br />
After it <span style="color: rgb(0, 0, 255);">is</span> packed, you need to then deploy
it. I took the sample script from here on the azure cmdlets project and then called <span style="color: rgb(0, 0, 255);">out</span> to
it from the TfsBuild.proj script like <span style="color: rgb(0, 0, 255);">this</span>:<br /><br />
&lt;DeployCommand&gt; 
<br />
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -command C:\Builds\1\AzureFacebook\AzureFacebookAzureDeploy\Sources\AzureFacebook\TfsBuild\deploy.ps1
C:\Builds\1\AzureFacebook\AzureFacebookAzureDeploy\Binaries\Release\ azurefacebook 
<br />
&lt;/DeployCommand&gt;<br /></pre>
          <br />
        </div>
        <p>
I wont go through the entire powershell script since it is documented here: <a href="http://code.msdn.microsoft.com/azurecmdlets">Windows
Azure Service Management CmdLets</a> , but I will show you what I changed.  First
I created some variables that i could pass in from the command line so that I could
reuse this script on all of our Azure Projects.
</p>
        <div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 600px; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper">
          <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;" id="codeSnippet">$buildPath = $args[0] 
<br />
$servicename = $args[1] 
<br />
$package = $buildPath + $servicename + <span style="color: rgb(0, 96, 128);">".cspkg"</span><br />
$config = $buildPath + <span style="color: rgb(0, 96, 128);">"ServiceConfiguration.cscfg"</span><br />
$a = Get-Date 
<br />
$buildLabel = $a.ToShortDateString() + <span style="color: rgb(0, 96, 128);">"-"</span> +
$a.ToShortTimeString()</pre>
          <br />
        </div>
        <p>
So now when it deploys it will create a label with the date and time it was deployed
which is very useful when in Azure so you can see the last time you deployed.
</p>
        <p>
You can download these scripts on our new Project on Codeplex that I worked with Microsoft
on called the <a href="http://facebookazuretoolkit.codeplex.com/">Facebook Azure Toolkit</a>.  <a href="http://scottdensmore.typepad.com/">Scott
Densmore</a> helped me create this awesome framework that makes it much easier to
write apps for Azure.  There are a lot of useful libraries and scripts in that
project that have nothing to do with Facebook, but more for Azure.  We are probably
going to create another project on Codeplex that is just an Azure Toolkit.  This
build script will be more refactored in the future, but wanted to get it out now for
those looking to do this now.  More to come…
</p>
        <img width="0" height="0" src="http://www.jimzimmerman.com/blog/aggbug.ashx?id=d2f2d519-f49d-4f05-80b8-132279151859" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Proposed Session at MIX 10 on Facebook in .NET</title>
    <link rel="alternate" type="text/html" href="http://www.jimzimmerman.com/blog/2010/01/13/Proposed+Session+At+MIX+10+On+Facebook+In+NET.aspx" />
    <id>http://www.jimzimmerman.com/blog/PermaLink,guid,00009a71-6ccf-4d3d-80f4-411a454d5a09.aspx</id>
    <published>2010-01-12T21:47:04.1880000-05:00</published>
    <updated>2010-01-12T21:47:04.1880000-05:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I proposed a session for <a href="http://live.visitmix.com/">MIX10</a> this year on
How to develop Facebook apps in .NET and deploying them to Azure.  The last 6
months have been very hectic with delivering 3 highly scalable Facebook apps in Azure. 
I spoke at PDC 09 this year during a lunch session, which was a great time. 
Not as many people showed up as I thought, but 100 people is still a lot especially
when there were thousands of poeple waiting in line for their laptops during that
lunch.  Bad timing I guess, but it was a great first time speaking at an event
like that.  You can see what i talked about here: <a title="http://microsoftpdc.com/Sessions/SVC32" href="http://microsoftpdc.com/Sessions/SVC32">http://microsoftpdc.com/Sessions/SVC32</a> I
am the first 20 minutes talking about our app that we did for Outback Steakhouse.
</p>
        <p>
After I did a session two months ago at Tampa Code Camp on Facebook app development
in .NET, I realized there were a lot of people who wanted to learn about this stuff. 
So I decided to submit a session to <a href="http://live.visitmix.com/">MIX10</a> this
year and am very excited to be able to present there if I get enough votes. 
:)  Hope to see you at Mix if you and I are lucky enough to go!
</p>
        <p>
          <a href="http://visitmix.com/opencallvote/Entry?entryId=BUILDI100">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Mix10_Vote_grn_240" border="0" alt="Mix10_Vote_grn_240" src="http://www.jimzimmerman.com/blog/content/binary/WindowsLiveWriter/ProposedSessionatMIX10onFacebookin.NET_13254/Mix10_Vote_grn_240_3.jpg" width="184" height="244" />
          </a>
        </p>
        <img width="0" height="0" src="http://www.jimzimmerman.com/blog/aggbug.ashx?id=00009a71-6ccf-4d3d-80f4-411a454d5a09" />
      </div>
    </content>
  </entry>
  <entry>
    <title>PdfResult a custom ActionResult in ASP.NET MVC</title>
    <link rel="alternate" type="text/html" href="http://www.jimzimmerman.com/blog/2009/10/06/PdfResult+A+Custom+ActionResult+In+ASPNET+MVC.aspx" />
    <id>http://www.jimzimmerman.com/blog/PermaLink,guid,0649294f-cece-4fca-8d29-080435bd10bb.aspx</id>
    <published>2009-10-06T00:20:29.3905000-04:00</published>
    <updated>2009-10-06T00:20:29.3905000-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have been very bad about not blogging and not posting code from my recent talks. 
For that I apologize.  Let me say just one thing on that.  4 kids, ADD,
and shiny new toys. :)
</p>
        <p>
Ok, so several people have asked about generating pdf’s from html and css.  At
work, we needed this for receipts for registration among other things.  We found
a great tool from <a href="http://www.winnovative-software.com">Winnovative Software</a> that
works great with css and html and spitting out an almost perfect pdf.  
</p>
        <p>
We are using mvc in our solution, so we decided to come up with a custom ActionResult
so that it would make it very easy to return a pdf from an action call.
</p>
        <p>
Here is what the action looks like:
</p>
        <pre class="code">
          <span style="color: blue">public </span>PdfResult PdfForm() { <span style="color: blue">string </span>html
= <span style="color: blue">this</span>.CaptureActionHtml(<span style="color: blue">this</span>,
c =&gt; (ViewResult)c.PrintForm()); <span style="color: blue">return new </span>PdfResult(html, <span style="color: #a31515">"PdfForm"</span>, <span style="color: blue">true</span>);
} <span style="color: blue">public </span>ActionResult PrintForm() { <span style="color: blue">var </span>db
= <span style="color: blue">new </span>NorthwindDataContext(); <span style="color: #2b91af">List</span>&lt;Customer&gt;
customers = db.Customers.ToList&lt;Customer&gt;(); ViewData[<span style="color: #a31515">"customers"</span>]
= customers; <span style="color: blue">return </span>View(<span style="color: #a31515">"PrintForm"</span>);
}</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
 
</p>
        <p>
Notice the CaptureActionHtml.  I found this code on this <a href="http://mikehadlow.blogspot.com/2008/06/mvc-framework-capturing-output-of-view_05.html">blog
post</a> as I was trying to figure out a way to use asp.net mvc as the template engine
to save time for generating the html which the html to pdf tool needed.
</p>
        <p>
Here is the CaptureActionHtml class:
</p>
        <pre class="code">
          <span style="color: blue">using </span>System; <span style="color: blue">using </span>System.IO; <span style="color: blue">using </span>System.Web; <span style="color: blue">using </span>System.Web.Mvc; <span style="color: blue">namespace </span>HtmlHelperExamples
{ <span style="color: blue">public static class </span><span style="color: #2b91af">ControllerExtensions </span>{ <span style="color: gray">///
&lt;summary&gt; /// </span><span style="color: green">Captures the HTML output by
a controller action that returns a ViewResult </span><span style="color: gray">///
&lt;/summary&gt; /// &lt;typeparam name="TController"&gt;</span><span style="color: green">The
type of controller to execute the action on</span><span style="color: gray">&lt;/typeparam&gt;
/// &lt;param name="controller"&gt;</span><span style="color: green">The
controller</span><span style="color: gray">&lt;/param&gt; /// &lt;param name="action"&gt;</span><span style="color: green">The
action to execute</span><span style="color: gray">&lt;/param&gt; /// &lt;returns&gt;</span><span style="color: green">The
HTML output from the view</span><span style="color: gray">&lt;/returns&gt; </span><span style="color: blue">public
static string </span>CaptureActionHtml&lt;TController&gt;( <span style="color: blue">this </span>TController
controller, Func&lt;TController, ViewResult&gt; action) <span style="color: blue">where </span>TController
: Controller { <span style="color: blue">return </span>controller.CaptureActionHtml(controller, <span style="color: blue">null</span>,
action); } <span style="color: gray">/// &lt;summary&gt; /// </span><span style="color: green">Captures
the HTML output by a controller action that returns a ViewResult </span><span style="color: gray">///
&lt;/summary&gt; /// &lt;typeparam name="TController"&gt;</span><span style="color: green">The
type of controller to execute the action on</span><span style="color: gray">&lt;/typeparam&gt;
/// &lt;param name="controller"&gt;</span><span style="color: green">The
controller</span><span style="color: gray">&lt;/param&gt; /// &lt;param name="masterPageName"&gt;</span><span style="color: green">The
master page to use for the view</span><span style="color: gray">&lt;/param&gt; ///
&lt;param name="action"&gt;</span><span style="color: green">The action
to execute</span><span style="color: gray">&lt;/param&gt; /// &lt;returns&gt;</span><span style="color: green">The
HTML output from the view</span><span style="color: gray">&lt;/returns&gt; </span><span style="color: blue">public
static string </span>CaptureActionHtml&lt;TController&gt;( <span style="color: blue">this </span>TController
controller, <span style="color: blue">string </span>masterPageName, Func&lt;TController,
ViewResult&gt; action) <span style="color: blue">where </span>TController : Controller
{ <span style="color: blue">return </span>controller.CaptureActionHtml(controller,
masterPageName, action); } <span style="color: gray">/// &lt;summary&gt; /// </span><span style="color: green">Captures
the HTML output by a controller action that returns a ViewResult </span><span style="color: gray">///
&lt;/summary&gt; /// &lt;typeparam name="TController"&gt;</span><span style="color: green">The
type of controller to execute the action on</span><span style="color: gray">&lt;/typeparam&gt;
/// &lt;param name="controller"&gt;</span><span style="color: green">The
current controller</span><span style="color: gray">&lt;/param&gt; /// &lt;param name="targetController"&gt;</span><span style="color: green">The
controller which has the action to execute</span><span style="color: gray">&lt;/param&gt;
/// &lt;param name="action"&gt;</span><span style="color: green">The action
to execute</span><span style="color: gray">&lt;/param&gt; /// &lt;returns&gt;</span><span style="color: green">The
HTML output from the view</span><span style="color: gray">&lt;/returns&gt; </span><span style="color: blue">public
static string </span>CaptureActionHtml&lt;TController&gt;( <span style="color: blue">this </span>Controller
controller, TController targetController, Func&lt;TController, ViewResult&gt; action) <span style="color: blue">where </span>TController
: Controller { <span style="color: blue">return </span>controller.CaptureActionHtml(targetController, <span style="color: blue">null</span>,
action); } <span style="color: gray">/// &lt;summary&gt; /// </span><span style="color: green">Captures
the HTML output by a controller action that returns a ViewResult </span><span style="color: gray">///
&lt;/summary&gt; /// &lt;typeparam name="TController"&gt;</span><span style="color: green">The
type of controller to execute the action on</span><span style="color: gray">&lt;/typeparam&gt;
/// &lt;param name="controller"&gt;</span><span style="color: green">The
current controller</span><span style="color: gray">&lt;/param&gt; /// &lt;param name="targetController"&gt;</span><span style="color: green">The
controller which has the action to execute</span><span style="color: gray">&lt;/param&gt;
/// &lt;param name="masterPageName"&gt;</span><span style="color: green">The
name of the master page for the view</span><span style="color: gray">&lt;/param&gt;
/// &lt;param name="action"&gt;</span><span style="color: green">The action
to execute</span><span style="color: gray">&lt;/param&gt; /// &lt;returns&gt;</span><span style="color: green">The
HTML output from the view</span><span style="color: gray">&lt;/returns&gt; </span><span style="color: blue">public
static string </span>CaptureActionHtml&lt;TController&gt;( <span style="color: blue">this </span>Controller
controller, TController targetController, <span style="color: blue">string </span>masterPageName,
Func&lt;TController, ViewResult&gt; action) <span style="color: blue">where </span>TController
: Controller { <span style="color: blue">if </span>(controller == <span style="color: blue">null</span>)
{ <span style="color: blue">throw new </span><span style="color: #2b91af">ArgumentNullException</span>(<span style="color: #a31515">"controller"</span>);
} <span style="color: blue">if </span>(targetController == <span style="color: blue">null</span>)
{ <span style="color: blue">throw new </span><span style="color: #2b91af">ArgumentNullException</span>(<span style="color: #a31515">"targetController"</span>);
} <span style="color: blue">if </span>(action == <span style="color: blue">null</span>)
{ <span style="color: blue">throw new </span><span style="color: #2b91af">ArgumentNullException</span>(<span style="color: #a31515">"action"</span>);
} <span style="color: green">// pass the current controller context to orderController </span><span style="color: blue">var </span>controllerContext
= controller.ControllerContext; targetController.ControllerContext = controllerContext; <span style="color: green">//
replace the current context with a new context that writes to a string writer </span><span style="color: blue">var </span>existingContext
= System.Web.HttpContext.Current; <span style="color: blue">var </span>writer = <span style="color: blue">new </span><span style="color: #2b91af">StringWriter</span>(); <span style="color: blue">var </span>response
= <span style="color: blue">new </span>HttpResponse(writer); <span style="color: blue">var </span>context
= <span style="color: blue">new </span>HttpContext(existingContext.Request, response)
{User = existingContext.User}; System.Web.HttpContext.Current = context; <span style="color: green">//
execute the action </span><span style="color: blue">var </span>viewResult = action(targetController); <span style="color: green">//
change the master page name </span><span style="color: blue">if </span>(masterPageName
!= <span style="color: blue">null</span>) { viewResult.MasterName = masterPageName;
} <span style="color: green">// we have to set the controller route value to the name
of the controller we want to execute // because the ViewLocator class uses this to
find the correct view </span><span style="color: blue">var </span>oldController =
controllerContext.RouteData.Values[<span style="color: #a31515">"controller"</span>];
controllerContext.RouteData.Values[<span style="color: #a31515">"controller"</span>]
= <span style="color: blue">typeof</span>(TController).Name.Replace(<span style="color: #a31515">"Controller"</span>, <span style="color: #a31515">""</span>); <span style="color: green">//
execute the result </span>viewResult.ExecuteResult(controllerContext); <span style="color: green">//
restore the old route data </span>controllerContext.RouteData.Values[<span style="color: #a31515">"controller"</span>]
= oldController; <span style="color: green">// restore the old context </span>System.Web.HttpContext.Current
= existingContext; <span style="color: blue">return </span>writer.ToString(); } }
}</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
Here is the PdfResult class:
</p>
        <pre class="code">
          <span style="color: blue">using </span>System; <span style="color: blue">using </span>System.Collections.Generic; <span style="color: blue">using </span>System.Linq; <span style="color: blue">using </span>System.Web; <span style="color: blue">using </span>Winnovative.WnvHtmlConvert; <span style="color: blue">using </span>System.Text.RegularExpressions; <span style="color: blue">namespace </span>System.Web.Mvc
{ <span style="color: blue">public class </span><span style="color: #2b91af">PdfResult </span>:
ViewResult { <span style="color: blue">public string </span>ContentType { <span style="color: blue">get</span>; <span style="color: blue">set</span>;
} <span style="color: blue">public string </span>Content { <span style="color: blue">get</span>; <span style="color: blue">set</span>;
} <span style="color: blue">public string </span>OutputFileName { <span style="color: blue">get</span>; <span style="color: blue">set</span>;
} <span style="color: blue">public bool </span>ReturnAsAttachment { <span style="color: blue">get</span>; <span style="color: blue">set</span>;
} <span style="color: blue">public </span>PdfResult(<span style="color: blue">string </span>html, <span style="color: blue">string </span>outputFileName, <span style="color: blue">bool </span>returnAsAttachment)
{ <span style="color: green">// ViewResult vr = ar as ViewResult; </span><span style="color: blue">this</span>.ContentType
= <span style="color: #a31515">"application/pdf"</span>; <span style="color: blue">this</span>.Content
= html; <span style="color: blue">this</span>.OutputFileName = outputFileName; <span style="color: blue">this</span>.ReturnAsAttachment
= returnAsAttachment; } <span style="color: blue">public override void </span>ExecuteResult(ControllerContext
context) { context.HttpContext.Response.ContentType = ContentType; <span style="color: blue">string </span>baseURL
= <span style="color: #a31515">""</span>; <span style="color: blue">string </span>htmlString
= <span style="color: blue">this</span>.Content; <span style="color: blue">bool </span>selectablePDF
= <span style="color: blue">true</span>; <span style="color: green">// Create the
PDF converter. Optionally you can specify the virtual browser width as parameter.
//1024 pixels is default, 0 means autodetect </span>PdfConverter pdfConverter = <span style="color: blue">new </span>PdfConverter(); <span style="color: green">//
set the license key </span>pdfConverter.LicenseKey = <span style="color: #a31515">"yourkeyhere"</span>; <span style="color: green">//
set the converter options </span>pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait;
pdfConverter.PdfDocumentOptions.ShowHeader = <span style="color: blue">false</span>;
pdfConverter.PdfDocumentOptions.ShowFooter = <span style="color: blue">false</span>; <span style="color: green">//
set to generate selectable pdf or a pdf with embedded image </span>pdfConverter.PdfDocumentOptions.GenerateSelectablePdf
= selectablePDF; <span style="color: green">// Performs the conversion and get the
pdf document bytes that you can further // save to a file or send as a browser response
// The baseURL parameterhelps the converter to get the CSS files and images // referenced
by a relative URL in the HTML string. This option has efect only // if the HTML string
contains a valid HEAD tag. // The converter will automatically inserts a &lt;BASE
HREF="baseURL"&gt; tag. </span><span style="color: blue">byte</span>[] pdfBytes
= <span style="color: blue">null</span>; <span style="color: blue">if </span>(baseURL.Length
&gt; 0) { pdfBytes = pdfConverter.GetPdfBytesFromHtmlString(htmlString, baseURL);
} <span style="color: blue">else </span>{ pdfBytes = pdfConverter.GetPdfBytesFromHtmlString(htmlString);
} <span style="color: green">// send the PDF document as a response to the browser
for download // System.Web.HttpResponse response = System.Web.HttpContext.Current.Response; </span>context.HttpContext.Response.Clear(); <span style="color: green">//
this.OutputFileName = Regex.Replace(this.OutputFileName, " ", "_",
RegexOptions.IgnoreCase); // this.OutputFileName = StringHelper.StripNonAlphaNumeric(this.OutputFileName); </span>context.HttpContext.Response.AddHeader(<span style="color: #a31515">"Content-Type"</span>, <span style="color: #a31515">"application/pdf"</span>); <span style="color: blue">if </span>(<span style="color: blue">this</span>.ReturnAsAttachment)
{ context.HttpContext.Response.AddHeader(<span style="color: #a31515">"Content-Disposition"</span>, <span style="color: #a31515">"attachment;
filename=" </span>+ <span style="color: blue">this</span>.OutputFileName + <span style="color: #a31515">".pdf;
size=" </span>+ pdfBytes.Length.ToString()); } context.HttpContext.Response.Flush();
context.HttpContext.Response.BinaryWrite(pdfBytes); context.HttpContext.Response.Flush();
context.HttpContext.Response.End(); } } }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
 
</p>
        <p>
Hopefully this will help those of you who are wanting to generate the pdf’s using
html and css along with using the default mvc view engine as your template engine.
Enjoy!
</p>
        <img width="0" height="0" src="http://www.jimzimmerman.com/blog/aggbug.ashx?id=0649294f-cece-4fca-8d29-080435bd10bb" />
      </div>
    </content>
  </entry>
  <entry>
    <title>IEnumerable Extension Method for AutoMapper</title>
    <link rel="alternate" type="text/html" href="http://www.jimzimmerman.com/blog/2009/07/10/IEnumerable+Extension+Method+For+AutoMapper.aspx" />
    <id>http://www.jimzimmerman.com/blog/PermaLink,guid,75241bbd-f11c-4209-bca7-5a7f288a6a7f.aspx</id>
    <published>2009-07-10T00:38:52.7180000-04:00</published>
    <updated>2009-09-04T00:45:00.7817500-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have been using <a href="http://code.google.com/p/automapperhome/">AutoMapper</a> for
a few projects lately and just love its power and ease of use. My projects have become
not only simpler to manage, but easier to do the right thing. What I mean by right
thing, is creating ViewModels and Domain objects in my ASP.NET MVC projects. Although
it seems like extra work to create multiple classes that seem to do what seems like
the same thing, down the road it is a much better way to do things because of maintainability
of views and domain logic not interfering. I am not going to get into the reason you
would do this, but you can find out more <a href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/06/29/how-we-do-mvc-view-models.aspx">here</a>.
Jimmy Bogard has a great article here as to why ViewModels are so important.
</p>
        <p>
Sometimes when you do not want to have to create your maps ahead of time, it can be
useful to use an extension method on IEnumerable which will work with IQueryable and
any other Interface that implements IEnumerable . 
</p>
        <p>
An example is to map a complex query to a complex domain model. For instance, lets
say I want to do a complicated db query using linq:
</p>
        <pre class="code">
          <span style="color: blue">var </span>q = <span style="color: blue">from </span>c <span style="color: blue">in </span>db.Customers <span style="color: blue">select
new </span>{ c.CompanyName, c.ContactName, Orders = (<span style="color: blue">from </span>order <span style="color: blue">in </span>db.Orders <span style="color: blue">where </span>order.CustomerID
== c.CustomerID <span style="color: blue">select </span>order) }; <span style="color: #2b91af">AutoMapperHelper</span>.TryCreateMap&lt;<span style="color: #2b91af">Order</span>, <span style="color: #2b91af">MyOrder</span>&gt;(); <span style="color: blue">var </span>a
= q.ToModelList&lt;<span style="color: #2b91af">ComplexCustomer</span>&gt;();</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a>And here is the ComplexCustomer class
that AutoMapper maps to:
</p>
        <pre class="code">
          <span style="color: blue">public class </span>
          <span style="color: #2b91af">ComplexCustomer </span>{ <span style="color: blue">public
string </span>CompanyName { <span style="color: blue">get</span>; <span style="color: blue">set</span>;
} <span style="color: blue">public string </span>ContactName { <span style="color: blue">get</span>; <span style="color: blue">set</span>;
} <span style="color: blue">public </span><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">MyOrder</span>&gt;
Orders { <span style="color: blue">get</span>; <span style="color: blue">set</span>;
} }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
Notice the extension Method: ToModelList<t>
(). This will execute the query to a list then automap it dynamically to the anonymous
type or a defined type. 
</t></p>
        <p>
Here are the extension methods:
</p>
        <pre class="code">
          <span style="color: blue">public static </span>IList&lt;TDestination&gt;
ToModelList&lt;TDestination&gt;(<span style="color: blue">this </span>IEnumerable
query) { var output = <span style="color: blue">new </span>List&lt;TDestination&gt;();
var sourceType = query.GetType().GetGenericArguments()[0]; var destType = output.GetType().GetGenericArguments()[0]; <span style="color: blue">foreach </span>(var
src <span style="color: blue">in </span>query) { var mySrc = Mapper.DynamicMap(src,
sourceType, destType); output.Add(Mapper.DynamicMap&lt;TDestination&gt;(mySrc)); } <span style="color: blue">return </span>output;
}</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <div style="padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:04013eae-1d43-4526-a2d9-d1240b520cce" class="wlWriterEditableSmartContent">
          <div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
            <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code
Snippet
</div>
            <div style="background: #ddd; max-height: 300px; overflow: scroll; padding: 0">
              <ol style="background: #ffffff; margin: 0 0 0 35px; white-space: wrap">
                <li>
                  <span style="color:#0000ff">public</span>
                  <span style="color:#0000ff">static</span> IList&lt;TDestination&gt;
ToModelList&lt;TDestination&gt;(<span style="color:#0000ff">this</span> IEnumerable
query)</li>
                <li style="background: #f3f3f3">
{</li>
                <li>
var output = <span style="color:#0000ff">new</span> List&lt;TDestination&gt;();</li>
                <li style="background: #f3f3f3">
var sourceType = query.GetType().GetGenericArguments()[0];</li>
                <li>
var destType = output.GetType().GetGenericArguments()[0];</li>
                <li style="background: #f3f3f3">
                </li>
                <li>
                  <span style="color:#0000ff">foreach</span> (var src <span style="color:#0000ff">in</span> query)</li>
                <li style="background: #f3f3f3">
{</li>
                <li>
var mySrc = Mapper.DynamicMap(src, sourceType, destType);</li>
                <li style="background: #f3f3f3">
output.Add(Mapper.DynamicMap&lt;TDestination&gt;(mySrc));</li>
                <li>
}</li>
                <li style="background: #f3f3f3">
                </li>
                <li>
                  <span style="color:#0000ff">return</span> output;</li>
                <li style="background: #f3f3f3">
\</li>
              </ol>
            </div>
          </div>
        </div>
        <blockquote>
        </blockquote>
        <p>
There are two ways to use this extension, one is to tell the extension both the source
and destination generic classes or just pass in the destination and it will use dynamic
mapping to figure out what the source is. Notice that there also is a AutoMapperHelper
class which helps to find out if the map you want is already in memory since AutoMapper
stores the maps statically. We found that by not doing this it created a performance
issue.
</p>
        <p>
All in all, we are loving AutoMapper and I hope that others find this extension very
useful. I have already used it with SubSonic 3, EF 4 and Action Filter Atrributes
in an ASP.NET MVC Project.
</p>
        <img width="0" height="0" src="http://www.jimzimmerman.com/blog/aggbug.ashx?id=75241bbd-f11c-4209-bca7-5a7f288a6a7f" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Entity Framework and Creating a Reusable Abstraction</title>
    <link rel="alternate" type="text/html" href="http://www.jimzimmerman.com/blog/2009/05/18/Entity+Framework+And+Creating+A+Reusable+Abstraction.aspx" />
    <id>http://www.jimzimmerman.com/blog/PermaLink,guid,30684462-528b-43a2-b61b-6abb8af24a69.aspx</id>
    <published>2009-05-17T20:39:27.1248750-04:00</published>
    <updated>2009-05-17T20:39:27.1248750-04:00</updated>
    <category term="Code Camp" label="Code Camp" scheme="http://www.jimzimmerman.com/blog/CategoryView,category,Code%2BCamp.aspx" />
    <category term="Entity Framework" label="Entity Framework" scheme="http://www.jimzimmerman.com/blog/CategoryView,category,Entity%2BFramework.aspx" />
    <category term="ORM" label="ORM" scheme="http://www.jimzimmerman.com/blog/CategoryView,category,ORM.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I am currently working on an open source project called <a href="http://mycodecamp.codeplex.com/" target="_blank">MyCodeCamp</a> with <a href="http://www.lostechies.com/blogs/sean_chambers/" target="_blank">Sean
Chambers</a>, <a href="http://twitter.com/fabiousa7" target="_blank">Fabio Honigmann</a>,
and <a href="http://estebanfg.blogspot.com/" target="_blank">Esteban Garcia</a>. 
We decided to use ASP.NET MVC and Entity Framework (EF).  Although I use <a href="http://code.google.com/p/subsonicproject/downloads/list" target="_blank">SubSonic
2.2</a> and 3 beta at work, I thought this might be a good time to learn other ORM
type frameworks for comparison. I have used <a href="http://msdn.microsoft.com/en-us/library/bb425822.aspx" target="_blank">LINQ
To SQL</a> and <a href="https://www.hibernate.org/343.html" target="_blank">NHibernate</a> a
little also, but am not an expert by any means.  And since we want this project
to be accessible to as many as possible, we thought Entity Framework would be a good
choice seeing as Linq2Sql is getting folded into Entity Framework anyway.
</p>
        <p>
So, I don’t really know how most people use EF, but coming from working on SubSonic
3, I have some habits that I would like to keep, particularly, using a Repository&lt;T&gt;
like pattern.  After looking at all the code and classes I would have to write
if I did the traditional, IClassRepository and ClassRepository, I decided to make
Repository&lt;T&gt; work kind of like it does in SubSonic 3 with SubSonicRepository&lt;T&gt;. 
This was not as easy as I thought.
</p>
        <p>
First problem is when you want to update the model, you need to open up the .edmx
file in the designer which sometimes does not open and you have to reboot Visual Studio. 
And if you make major changes to your data model, you are better off deleting the
file and recreating it.  Now I don’t think that would go over to well if you
actually used it to do your mappings of data to entity models, but I am not using
Entity Framework that way.  I think it was their intention to use it more of
as a mapper, but I think I have found a much easier and scalable way of mapping data
to domain objects by using <a href="http://automapper.codeplex.com/" target="_blank">AutoMapper</a>. 
We use AutoMapper at work with SubSonic 3 and we just love it.  I won’t go into
everything it does, but it is by far the best project out there for mapping objects
to other objects.
</p>
        <p>
So here is an example of how I am getting an entity object, then mapping it to a domain
object.
</p>
        <pre class="code">
          <span style="color: blue">public class </span>
          <span style="color: #2b91af">Repository</span>&lt;T&gt;
: <span style="color: #2b91af">IRepository</span>&lt;T&gt; { <span style="color: blue">private </span>MyCodeCamp.Data.<span style="color: #2b91af">MyCodeCampEntities </span>context; <span style="color: blue">public </span>Repository()
{ context = <span style="color: blue">new </span>MyCodeCamp.Data.<span style="color: #2b91af">MyCodeCampEntities</span>();
} <span style="color: blue">public </span>T GetById(<span style="color: #2b91af">Int32 </span>id)
{ <span style="color: blue">var </span>tableName = <span style="color: blue">typeof</span>(T).Name; <span style="color: blue">var </span>key
= <span style="color: blue">new </span><span style="color: #2b91af">EntityKey</span>(<span style="color: #a31515">"MyCodeCampEntities." </span>+
tableName, <span style="color: #a31515">"Id"</span>, id); <span style="color: blue">var </span>r
= (T)context.GetObjectByKey(key); <span style="color: blue">return </span>r; } }</pre>
        <p>
Notice, since I am using T, I need to use reflection to get the Entity Name, or table
name.  Then this data returns to a BaseService&lt;TModel, T&gt;
</p>
        <a href="http://11011.net/software/vspaste">
        </a>
        <pre class="code">
          <span style="color: blue">using </span>System; <span style="color: blue">using </span>System.Collections.Generic; <span style="color: blue">using </span>System.Linq; <span style="color: blue">using </span>System.Text; <span style="color: blue">using </span>AutoMapper; <span style="color: blue">using </span>MyCodeCamp.Data; <span style="color: blue">namespace </span>MyCodeCamp.Domain.Services
{ <span style="color: blue">public abstract class </span><span style="color: #2b91af">BaseService</span>&lt;TModel,
T&gt; <span style="color: blue">where </span>TModel : <span style="color: blue">new</span>() <span style="color: blue">where </span>T
: <span style="color: blue">new</span>() { <span style="color: blue">public </span><span style="color: #2b91af">Repository</span>&lt;T&gt;
_repo; <span style="color: blue">protected </span>BaseService() { _repo = <span style="color: blue">new </span><span style="color: #2b91af">Repository</span>&lt;T&gt;(); <span style="color: green">//
Cache maps </span><span style="color: blue">var </span>tm = <span style="color: #2b91af">Mapper</span>.FindTypeMapFor&lt;T,
TModel&gt;(); <span style="color: blue">if </span>(tm == <span style="color: blue">null</span>)
{ <span style="color: #2b91af">Mapper</span>.CreateMap&lt;T, TModel&gt;(); } tm = <span style="color: #2b91af">Mapper</span>.FindTypeMapFor&lt;TModel,
T&gt;(); <span style="color: blue">if </span>(tm == <span style="color: blue">null</span>)
{ <span style="color: #2b91af">Mapper</span>.CreateMap&lt;TModel, T&gt;(); } } <span style="color: blue">public
virtual </span>TModel GetById(<span style="color: #2b91af">Int32 </span>id) { <span style="color: blue">var </span>item
= _repo.GetById(id); <span style="color: blue">var </span>model = Map(item); <span style="color: blue">return </span>model;
} <span style="color: blue">public virtual </span>TModel Map(T d) { <span style="color: blue">return </span><span style="color: #2b91af">Mapper</span>.Map&lt;T,
TModel&gt;(d); } } }</pre>
        <p>
Now for the service that derives form the BaseService:
</p>
        <pre class="code">
          <span style="color: blue">public class </span>
          <span style="color: #2b91af">VenueService </span>: <span style="color: #2b91af">BaseService</span>&lt;Model.<span style="color: #2b91af">Venue</span>,
Data.<span style="color: #2b91af">Venue</span>&gt; { <span style="color: blue">public </span>VenueService()
{ } <span style="color: blue">public </span><span style="color: #2b91af">List</span>&lt;Model.<span style="color: #2b91af">Venue</span>&gt;
GetByCity(<span style="color: blue">string </span>city) { <span style="color: blue">var </span>result
= _repo.Find(v =&gt; v.City == city); <span style="color: blue">var </span>venues
= result.ToList(); <span style="color: blue">var </span>venueModels = Map(venues); <span style="color: blue">return </span>venueModels;
} }</pre>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a>As you can see the Code is very clean
and simple to read.  What is nice about going down this road with the AutoMapper
is that mapping is completely automated and I don’t have to remap anything if I change
properties or add them to the data model.  All I need to do is make sure the
Property is on the domain model, then it will get mapped.  Also it will map by
convention also, so if you have a Complex type as a property, like, Venue.Room.Name
it would automatically map to a flattened dto like Venue.RoomName.  There are
a ton of other conventions also, but you should go download AutoMapper and look at
the tests to see all of the possibilities.
</p>
        <p>
The next big issue I ran into was that the data was not getting updated when I would
pass a detached object to the EF context.  Since I was creating the object that
needed to get passed in outside of the ObjectContext scope, I needed to get the EF
ObjectStateManager to recognize that the Entity Object had changed and to persist
it.  I again had to use a little bit of reflection, but after I understood how
EF handled things, it made more sense.  It was quite frustrating for a few hours
trying to figure out why EF was not persisting updates and only inserts.  As
you can see with the code below I needed to get the value of the Entity Key and the
hydrate the entity object so that the ObjectStateManager knew that the data had been
changed.
</p>
        <pre class="code">
          <span style="color: blue">public int </span>Update(T o) { <span style="color: blue">var </span>tableName
= <span style="color: blue">typeof</span>(T).Name; <span style="color: green">// Need
to get object out of ObjectStateManager, then set it so the dbcontext knows to persist
changes </span><span style="color: blue">var </span>Id = GetPrimaryKeyValue(o); T
currentObject = GetById(Id); currentObject = o; context.ApplyPropertyChanges(tableName,
currentObject); <span style="color: blue">return </span>context.SaveChanges(); } <span style="color: blue">private
int </span>GetPrimaryKeyValue(T o) { <span style="color: blue">int </span>Id = 0; <span style="color: blue">var </span>properties
= <span style="color: blue">typeof</span>(T).GetProperties(); <span style="color: blue">foreach </span>(<span style="color: #2b91af">PropertyInfo </span>p <span style="color: blue">in </span>properties)
{ <span style="color: blue">if </span>(<span style="color: blue">string</span>.Compare(p.Name, <span style="color: #a31515">"Id"</span>, <span style="color: blue">true</span>)
== 0) { <span style="color: blue">var </span>r = p.GetValue(o, <span style="color: blue">null</span>).ToString();
Id = <span style="color: blue">int</span>.Parse(r); <span style="color: blue">break</span>;
} } <span style="color: blue">return </span>Id; }</pre>
All in all, I don’t mind EF for the Data Access Mapping, and the way it is currently
abstracted in our project, it could easily be switched out for Linq To Sql, Subsonic,
or any other ORM that uses LINQ to access its data.  I think the best way to
use Data Mapping technologies in the future is control your own mapping by using tools
such as AutoMapper so that you are not locked in to one way of getting your data out
of your database.  <img width="0" height="0" src="http://www.jimzimmerman.com/blog/aggbug.ashx?id=30684462-528b-43a2-b61b-6abb8af24a69" /></div>
    </content>
  </entry>
  <entry>
    <title>Modifying a compile asp.net assembly when no longer have source</title>
    <link rel="alternate" type="text/html" href="http://www.jimzimmerman.com/blog/2009/03/25/Modifying+A+Compile+Aspnet+Assembly+When+No+Longer+Have+Source.aspx" />
    <id>http://www.jimzimmerman.com/blog/PermaLink,guid,789af1a1-9fa7-4c15-91df-f22a49084c1d.aspx</id>
    <published>2009-03-24T23:42:51.2348750-04:00</published>
    <updated>2009-03-24T23:42:51.2348750-04:00</updated>
    <category term="ASP.NET" label="ASP.NET" scheme="http://www.jimzimmerman.com/blog/CategoryView,category,ASP.NET.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
So while I was at the MVP Summit, an old client got a hold of me and said there was
a weird error on the site when a user was trying to post something.  He sent
me a screenshot and it said could not login as sa to sql server.  I remoted into
the server where they had moved the application and looked in the web.config file
and did not see any connection string that had sa as the user name.  So I was
stumped.  I began to look at the stack trace and realized which assembly this
was coming from.  This happened to be the only assembly which did not have the
source code on the server.  I wrote the app over 6 years ago and the laptop the
source was on had recently had a failed hard drive.
</p>
        <p>
Anyway, it was a vb.net 1.1 app from visual studio 2003.  Yes I used to do a
little VB. :)  So I realized that there must have been a connection string hard
coded in the assembly where the stack trace was coming from.  Oh no!  How
was i going to fix this without changing the sa password on their new host which was
not really an option?  
</p>
        <p>
First thing I did was download reflector <a href="http://www.red-gate.com/products/reflector/" target="_blank">here</a>.
I opened the assembly and did see the hard code connection string.  Man what
an idiot for doing that.  Don’t know why I did that at the time, but not a very
smart move. So I was stuck.  How do I edit an assembly without having to export
all the code from reflector, find visual studio 2003 and run it in a virtual, download
the rest of the app and pray that I could get it to work.  Well i searched for
modifying a .net assembly and found this: Reflexil - <a href="http://sebastien.lebreton.free.fr/reflexil/" target="_blank">http://sebastien.lebreton.free.fr/reflexil/</a> .
It is a plug-in that works inside of reflector that allows the modification of the
code in the assembly.  So i downloaded it opened the assembly, changed the connection
string code and then saved it.  The .dll ended up being a third the size, but
still worked after deploying it to the server.  I was shocked.  I just had
edited a vb.net 1.1 assembly on a windows 7 laptop using reflector while in a session
during the MVP summit.  Pretty cool I think.  Saved me a whole day of figuring
out how to run visual studio 2003 and get that code compiled again.
</p>
        <img width="0" height="0" src="http://www.jimzimmerman.com/blog/aggbug.ashx?id=789af1a1-9fa7-4c15-91df-f22a49084c1d" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Windows 7 and My 2 year old Laptop</title>
    <link rel="alternate" type="text/html" href="http://www.jimzimmerman.com/blog/2009/02/24/Windows+7+And+My+2+Year+Old+Laptop.aspx" />
    <id>http://www.jimzimmerman.com/blog/PermaLink,guid,68861d34-52bc-43ca-92f5-2de4da946055.aspx</id>
    <published>2009-02-23T23:00:35.8588750-05:00</published>
    <updated>2009-02-23T23:00:35.8588750-05:00</updated>
    <category term="Windows7" label="Windows7" scheme="http://www.jimzimmerman.com/blog/CategoryView,category,Windows7.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have owned a Dell Inspiron 9400 for almost 2 years with Vista Ultimate and have
enjoyed it for the most part.  I had some issues with wireless and getting the
sluggish feeling after I had visual studio, 20 browser tabs open, iis 7, sql server,
etc. all open at the same time.  Of course I thought, well i have a lot of stuff
running at same time so of course it will be slower.  Well now with Windows 7
I have not one wireless issue, speed is crazy faster and I  am still only using
1 gb of ram of 2 gb available.  
</p>
        <p>
I am absolutely shocked a how much better I like my laptop.  I have a 8 Gb Vista
64 desktop at home, so my laptop is always going to seem sluggish, but now I really
like using my laptop.  I am not looking forward to having to wipe it again when
the beta expires, but is well worth the joy i now get from my laptop.  
</p>
        <p>
          <a href="http://www.jimzimmerman.com/blog/content/binary/WindowsLiveWriter/Windows7andmy2yearoldlaptop_12EF0/Windows7DesktopSmall_2.jpg">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Windows7DesktopSmall" border="0" alt="Windows7DesktopSmall" src="http://www.jimzimmerman.com/blog/content/binary/WindowsLiveWriter/Windows7andmy2yearoldlaptop_12EF0/Windows7DesktopSmall_thumb.jpg" width="244" height="154" />
          </a>
        </p>
        <p>
I love the new task bar and my favorites always being down there.  I can’t remember
if I have even done a full reboot in a month.  Oh if you are going to try this
at home, make sure to do a clean install.  
</p>
        <img width="0" height="0" src="http://www.jimzimmerman.com/blog/aggbug.ashx?id=68861d34-52bc-43ca-92f5-2de4da946055" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Enabling 301 redirects on IIS 7 on Windows server 2008</title>
    <link rel="alternate" type="text/html" href="http://www.jimzimmerman.com/blog/2009/02/05/Enabling+301+Redirects+On+IIS+7+On+Windows+Server+2008.aspx" />
    <id>http://www.jimzimmerman.com/blog/PermaLink,guid,3d7d763e-b8c5-4900-9139-1cdaadf88e70.aspx</id>
    <published>2009-02-05T00:37:27.7335000-05:00</published>
    <updated>2009-02-05T00:37:27.7335000-05:00</updated>
    <category term="IIS 7" label="IIS 7" scheme="http://www.jimzimmerman.com/blog/CategoryView,category,IIS%2B7.aspx" />
    <category term="Windows Server 2008" label="Windows Server 2008" scheme="http://www.jimzimmerman.com/blog/CategoryView,category,Windows%2BServer%2B2008.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I was stumped the other day as to why i could not get a 301 redirect in from site.com
to <a href="http://www.site.com">www.site.com</a> on IIS 7.  After much looking
around I found out that you need to enable this feature in the server manager.  
</p>
        <p>
          <a href="http://www.jimzimmerman.com/blog/content/binary/WindowsLiveWriter/Enabling301redirectsonIIS7onWindowsserve_DEE8/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jimzimmerman.com/blog/content/binary/WindowsLiveWriter/Enabling301redirectsonIIS7onWindowsserve_DEE8/image_thumb.png" width="694" height="263" />
          </a>
        </p>
        <p>
Then you need to go back to the IIS node that you want to enable 301 redirect for:
</p>
        <p>
 
</p>
        <p>
          <a href="http://www.jimzimmerman.com/blog/content/binary/WindowsLiveWriter/Enabling301redirectsonIIS7onWindowsserve_DEE8/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jimzimmerman.com/blog/content/binary/WindowsLiveWriter/Enabling301redirectsonIIS7onWindowsserve_DEE8/image_thumb_1.png" width="659" height="374" />
          </a>
        </p>
        <p>
And then set the values for your redirect:
</p>
        <p>
          <a href="http://www.jimzimmerman.com/blog/content/binary/WindowsLiveWriter/Enabling301redirectsonIIS7onWindowsserve_DEE8/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jimzimmerman.com/blog/content/binary/WindowsLiveWriter/Enabling301redirectsonIIS7onWindowsserve_DEE8/image_thumb_2.png" width="445" height="322" />
          </a>
        </p>
        <p>
If you notice what is also cool is that it will redirect addresses relative to the
domain and not just to the root (i.e <a href="http://www.site.com/oldfile.htm">site.com/oldfile.htm</a> will
redirect to <a href="http://www.site.com/oldfile.htm">www.site.com/oldfile.htm</a>.  
</p>
        <p>
Hope this helps someone, cause it was not very intuitive for me to find out how to
do it since the feature was not installed by default.
</p>
        <img width="0" height="0" src="http://www.jimzimmerman.com/blog/aggbug.ashx?id=3d7d763e-b8c5-4900-9139-1cdaadf88e70" />
      </div>
    </content>
  </entry>
  <entry>
    <title>ASP.NET MVC 1.0 Release Candidate Is Released</title>
    <link rel="alternate" type="text/html" href="http://www.jimzimmerman.com/blog/2009/01/28/ASPNET+MVC+10+Release+Candidate+Is+Released.aspx" />
    <id>http://www.jimzimmerman.com/blog/PermaLink,guid,2abed4ad-eb56-4857-be29-3fdc026aa95b.aspx</id>
    <published>2009-01-27T22:31:47.4840000-05:00</published>
    <updated>2009-01-27T23:46:24.8122500-05:00</updated>
    <category term="ASP.NET" label="ASP.NET" scheme="http://www.jimzimmerman.com/blog/CategoryView,category,ASP.NET.aspx" />
    <category term="ASP.NET MVC" label="ASP.NET MVC" scheme="http://www.jimzimmerman.com/blog/CategoryView,category,ASP.NET%2BMVC.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Time to dig into the T4 template system (learn <a href="http://www.hanselman.com/blog/T4TextTemplateTransformationToolkitCodeGenerationBestKeptVisualStudioSecret.aspx">here</a>)
in Visual Studio since they added a cool feature for generating scaffold controllers
and views. Check out <a href="http://weblogs.asp.net/scottgu/archive/2009/01/27/asp-net-mvc-1-0-release-candidate-now-available.aspx">ScottGu's
Article</a>, of course. I am thinking that this was influenced by the <a href="http://blog.wekeroad.com/blog/subsonic-mvc-scaffold-addin/">SubSonic
MVC Scaffold Addin</a> from Rob Conery a little bit ago. I am so happy that we are
going to have our own scaffold playground with built in tools. It is getting so much
closer to how I really want to develop web apps. Woohoo! 
</p>
        <p>
I know it has been a long time since i blogged, since before the holidays. Four kids
is a little bit busier than I imagined, but all worth it. I am still trying to stay
up late to learn more new things coming out in the web world, as I love the information
overload. Much more to come soon I am sure! 
</p>
        <p>
Just found this link. You will need this to check out the <a href="http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=22359">MVC
futures</a> stuff that has Html.TextBoxFor(p =&gt; p.PropteryName). 
</p>
        <img width="0" height="0" src="http://www.jimzimmerman.com/blog/aggbug.ashx?id=2abed4ad-eb56-4857-be29-3fdc026aa95b" />
      </div>
    </content>
  </entry>
  <entry>
    <title>How to speed up your ASP.NET Website</title>
    <link rel="alternate" type="text/html" href="http://www.jimzimmerman.com/blog/2008/12/10/How+To+Speed+Up+Your+ASPNET+Website.aspx" />
    <id>http://www.jimzimmerman.com/blog/PermaLink,guid,56e866cd-268f-4794-80f1-f9ece418eb33.aspx</id>
    <published>2008-12-09T23:52:17.4220000-05:00</published>
    <updated>2008-12-09T23:52:17.4220000-05:00</updated>
    <category term="ASP.NET" label="ASP.NET" scheme="http://www.jimzimmerman.com/blog/CategoryView,category,ASP.NET.aspx" />
    <category term="ASP.NET MVC" label="ASP.NET MVC" scheme="http://www.jimzimmerman.com/blog/CategoryView,category,ASP.NET%2BMVC.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently we noticed that our site was a little sluggish.  Now of course when
we started to look at why it was slow sometimes and not others, we opened up a huge
can of worms.  Was it our code?  Was it our server?  Was it our proxy
server?  Was it our database?  Was it our graphics?  Was it the JavaScript? 
Or was it just that the end user had a slow connection?  Well it was all of them.  
</p>
        <p>
Sometimes we forget that not everyone has FIOS.  We are very lucky to have a
20 Mbps / 20 Mbps connection at work.  So first thing we did was to look at the
size of our pages when downloading the html, CSS, images and JavaScript.  We
were shocked at the size of the files.  The first eye opening fact was that our
home page was 1.5 MB.  Whoa.  The best tool that we found to figure the
details out was <a href="http://developer.yahoo.com/yslow/">YSlow</a>.  Here
is a snippet from their site about what the tool does:
</p>
        <blockquote>
          <p>
YSlow analyzes web pages and tells you why they're slow based on the <a href="http://developer.yahoo.com/performance/index.html#rules">rules
for high performance web sites</a>. YSlow is a <a href="https://addons.mozilla.org/en-US/firefox/addon/5369">Firefox
add-on</a> integrated with the popular <a href="http://www.getfirebug.com/">Firebug</a> web
development tool
</p>
        </blockquote>
        <p>
This tool saved us so much time figuring out what our issues were.  I highly
suggest reading the rules.  Also you can listen to a recent podcast from DotNetRocks: <a href="http://www.dotnetrocks.com/default.aspx?showNum=390">YSlow!
Steve Souders finds Website Bottlenecks</a></p>
        <p>
So we began the process of optimizing the client.  The first thing you can do
is to compress the JavaScript, CSS and html files on the server to reduce the file
download size up to 75% on the client.  The way to do this in IIS6 is to enable
GZip compression.  This is turned off by default which I think should actually
be turned on by default.  Here is some info on how to enable it for specific
file types.  Don't forget the .axd files if you use and Ajax in webforms. 
</p>
        <p>
        </p>
        <a href="http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/25d2170b-09c0-45fd-8da4-898cf9a7d568.mspx?mfr=true">Using
HTTP Compression for Faster Downloads (IIS 6.0)</a>
        <p>
So next on our list was minimizing the size of the images that we were using as backgrounds
in CSS.  They are the first calls from the browser when loaded from CSS. 
Also moving JavaScript references to the bottom of the page helps.  The browser
using a blocking request when loading JavaScript files, so if you have them at the
top of the page, you will get a perceived load issue since the browser waits for that
first.  The best thing to get out of optimizing for the client is the perceived
load to the user which really makes the most difference.
</p>
        <p>
So after removing the client side issues we realized we had a database load issue
on certain pages with many records.  Well we found out we ran into the famous
ORM gotcha of way too many queries when using strictly the data objects with related
foreign key objects.  For instance, by relating a member record to the aspnet
user table and doing a foreach on the member and then checking to see their username
on the aspnet user table, it will cause another db query to get that info for each
user.  Sometimes when using the orm objects that are generated instead of writing
a custom query to populate your own domain object, you can get into a lot of trouble.
</p>
        <p>
Our website has many applications to it, some mvc and some using webforms.  We
have noticed a significant speed increase on the mvc sites.  There is less code
to render and there is no Viewstate so right away there is some performance increases.  
</p>
        <p>
I hope that this helps some other people figure out why their site is slow for some
people some of the time.
</p>
        <img width="0" height="0" src="http://www.jimzimmerman.com/blog/aggbug.ashx?id=56e866cd-268f-4794-80f1-f9ece418eb33" />
      </div>
    </content>
  </entry>
</feed>
