<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>RickAndMSFT on Azure &amp; MVC</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/rickandy/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/rickandy/feed.xml</link>
    <description>Filling the Azure Gap</description>
    <lastBuildDate>Thu, 02 Apr 2015 03:29:23 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Seeding and Debugging Entity Framework (EF) DBs</title>
      <link>https://docs.microsoft.com/archive/blogs/rickandy/seeding-and-debugging-entity-framework-ef-dbs</link>
      <pubDate>Tue, 12 Feb 2013 16:45:30 GMT</pubDate>
      <dc:creator><![CDATA[Rick_Anderson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rickandy/2013/02/12/seeding-and-debugging-entity-framework-ef-dbs/</guid>
      <description><![CDATA[In Tom Dykstra’s terrific ASP.NET MVC EF tutorial, the following code is used to seed the student...]]></description>
      <content:encoded><![CDATA[<p>In Tom Dykstra’s terrific <a href="https://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application" target="_blank">ASP.NET MVC EF</a> tutorial, the following code is used to seed the student table.</p>  <pre class="code"><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">students = </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">List</span><span style="background: white; color: black;">&lt;</span><span style="background: white; color: rgb(43, 145, 175);">Student</span><span style="background: white; color: black;">&gt;
{
    </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">Student </span><span style="background: white; color: black;">{ FirstMidName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Carson&quot;</span><span style="background: white; color: black;">,   LastName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Alexander&quot;</span><span style="background: white; color: black;">, EnrollmentDate = </span><span style="background: white; color: rgb(43, 145, 175);">DateTime</span><span style="background: white; color: black;">.Parse(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;2005-09-01&quot;</span><span style="background: white; color: black;">) },
    </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">Student </span><span style="background: white; color: black;">{ FirstMidName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Meredith&quot;</span><span style="background: white; color: black;">, LastName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Alonso&quot;</span><span style="background: white; color: black;">,    EnrollmentDate = </span><span style="background: white; color: rgb(43, 145, 175);">DateTime</span><span style="background: white; color: black;">.Parse(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;2002-09-01&quot;</span><span style="background: white; color: black;">) },
    </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">Student </span><span style="background: white; color: black;">{ FirstMidName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Arturo&quot;</span><span style="background: white; color: black;">,   LastName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Anand&quot;</span><span style="background: white; color: black;">,     EnrollmentDate = </span><span style="background: white; color: rgb(43, 145, 175);">DateTime</span><span style="background: white; color: black;">.Parse(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;2003-09-01&quot;</span><span style="background: white; color: black;">) },
    </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">Student </span><span style="background: white; color: black;">{ FirstMidName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Gytis&quot;</span><span style="background: white; color: black;">,    LastName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Barzdukas&quot;</span><span style="background: white; color: black;">, EnrollmentDate = </span><span style="background: white; color: rgb(43, 145, 175);">DateTime</span><span style="background: white; color: black;">.Parse(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;2002-09-01&quot;</span><span style="background: white; color: black;">) },
    </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">Student </span><span style="background: white; color: black;">{ FirstMidName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Yan&quot;</span><span style="background: white; color: black;">,      LastName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Li&quot;</span><span style="background: white; color: black;">,        EnrollmentDate = </span><span style="background: white; color: rgb(43, 145, 175);">DateTime</span><span style="background: white; color: black;">.Parse(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;2002-09-01&quot;</span><span style="background: white; color: black;">) },
    </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">Student </span><span style="background: white; color: black;">{ FirstMidName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Peggy&quot;</span><span style="background: white; color: black;">,    LastName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Justice&quot;</span><span style="background: white; color: black;">,   EnrollmentDate = </span><span style="background: white; color: rgb(43, 145, 175);">DateTime</span><span style="background: white; color: black;">.Parse(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;2001-09-01&quot;</span><span style="background: white; color: black;">) },
    </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">Student </span><span style="background: white; color: black;">{ FirstMidName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Laura&quot;</span><span style="background: white; color: black;">,    LastName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Norman&quot;</span><span style="background: white; color: black;">,    EnrollmentDate = </span><span style="background: white; color: rgb(43, 145, 175);">DateTime</span><span style="background: white; color: black;">.Parse(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;2003-09-01&quot;</span><span style="background: white; color: black;">) },
    </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">Student </span><span style="background: white; color: black;">{ FirstMidName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Nino&quot;</span><span style="background: white; color: black;">,     LastName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Olivetto&quot;</span><span style="background: white; color: black;">,  EnrollmentDate = </span><span style="background: white; color: rgb(43, 145, 175);">DateTime</span><span style="background: white; color: black;">.Parse(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;2005-09-01&quot;</span><span style="background: white; color: black;">) },
};

 students.ForEach(s =&gt; context.Students.AddOrUpdate(p =&gt; p.LastName, s));
 context.SaveChanges();</span>&#160;</pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>
The <a href="https://msdn.microsoft.com/en-us/library/hh846520(v=vs.103).aspx" target="_blank">AddOrUpdate</a> method should generally only be used to seed a DB,&#160; you it cautiously for upsets in your code or you run the risk of losing data. ( For more information see <a href="https://thedatafarm.com/blog/data-access/take-care-with-ef-4-3-addorupdate-method/">Take care with EF 4.3 AddOrUpdate Method</a> on Julie Lerman's blog.) Tom states: 

<blockquote>
  <p><em>The first parameter passed to the </em><a href="https://msdn.microsoft.com/en-us/library/hh846520(v=vs.103).aspx" target="_blank"><em>AddOrUpdate</em></a><em> method specifies the property to use to check if a row already exists. For the test student data that we are providing, the LastName property can be used for this purpose since each last name in the list is unique.</em></p>
</blockquote>

<p>An important consideration in many applications is how you handle nearly duplicate data. For example,&#160; how will your application work when you have two students named Alexander Carson. Even very small databases like the NFL players have several members with exactly the same name (for example <a href="https://www.nfl.com/player/stevesmith/2504595/profile" target="_blank">Steve Smith of the Carolina Panthers</a> and <a href="https://www.nfl.com/player/stevesmith/2507175/profile" target="_blank">Steve Smith of the St. Louis Rams</a>).</p>

<p>Using the code above, you can’t add another Alexander Carson. You can add another Alexander Carson who enrolled on a different date from the first entry with the following code:</p>

<pre class="code"><span style="background: white; color: blue;">foreach </span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(43, 145, 175);">Student </span><span style="background: white; color: black;">e </span><span style="background: white; color: blue;">in </span><span style="background: white; color: black;">students)
{
    </span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">studentInDB = context.Students.Where(
        s =&gt; s.FirstMidName == e.FirstMidName &amp;&amp;
        s.LastName == e.LastName  &amp;&amp;
        s.EnrollmentDate == e.EnrollmentDate).SingleOrDefault();
      
    </span><span style="background: white; color: blue;">if </span><span style="background: white; color: black;">(studentInDB == </span><span style="background: white; color: blue;">null</span><span style="background: white; color: black;">)
    {
        context.Students.Add(e);
    }
}

context.SaveChanges();</span>
</pre>

<p>While the code above solves the problem of adding another Alexander Carson, it’s not a general solution. You can’t add another Alexander Carson with a duplicate enrolment date. An approach I like to take, especially with larger seed databases, is to add each record one at a time. The following code shows how to do this:</p>

<pre class="code"><span style="background: white; color: black;">context.Students.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">Student </span><span style="background: white; color: black;">{ FirstMidName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Carson&quot;</span><span style="background: white; color: black;">, LastName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Alexander&quot; </span><span style="background: white; color: black;">});
context.SaveChanges();
context.Students.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">Student </span><span style="background: white; color: black;">{ FirstMidName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Carson&quot;</span><span style="background: white; color: black;">, LastName = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Alexander&quot; </span><span style="background: white; color: black;">});
context.SaveChanges();</span></pre>

<p>You don’t need to call <a href="https://msdn.microsoft.com/en-us/library/bb336792.aspx" target="_blank">SaveChanges</a> after each Add, but doing so will show you exactly where a problem occurs. For example, when I was working on <a href="https://weblogs.asp.net/jgalloway/" target="_blank">Jon Galloway’s</a> fabulous <a href="https://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-1" target="_blank">MVC Music Store tutorial</a>, I added a minimum string length constraint of 2. Everything worked fine, the constraint worked, I couldn’t add new albums with a name less than 2 characters. At some point I migrated the code to a new system where the migrations code had to insert all the seed data into the DB. The initializer failed with an obscure error. Switching the code to the Add/SaveChanges approach quickly exposed the problem (there was a seed album with a one character name).</p>

<p>While working on this blog, I was getting the following error when running <strong>update-database</strong> from the Package Manager Console.</p>

<p><font color="#ff0000">Sequence contains more than one element</font></p>

<p>I couldn’t see how there was any duplicates in my code, so I went into debug mode. Adding <a href="https://msdn.microsoft.com/en-us/library/ea9yy3ey.aspx" target="_blank">System.Diagnostics.Debugger.Break();</a> to the migrations code caused Visual Studio to shut down and restart. I just happened to see Rowan in the kitchen and he suggested I look at his blog <a href="https://romiller.com/2012/02/09/running-scripting-migrations-from-code/" target="_blank">Running &amp; Scripting Migrations From Code</a>. I copy/pasted the following lines from his blog into the <strong>about</strong> method of my controller and was able to step into and debug the seed method.</p>

<pre class="code"><span style="background: white; color: blue;">public </span><span style="background: white; color: rgb(43, 145, 175);">ActionResult </span><span style="background: white; color: black;">About()
{
   <mark> </mark></span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">configuration = </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">Configuration</span><span style="background: white; color: black;">();
    </span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">migrator = </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">DbMigrator</span><span style="background: white; color: black;">(configuration);
    migrator.Update();
    ViewBag.Message = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Your app description page.&quot;</span><span style="background: white; color: black;">;

    </span><span style="background: white; color: blue;">return </span><span style="background: white; color: black;">View();
}</span></pre>

<p> It was an excellent message, I had previously added duplicates of Alexander Carson with the Add method, and subsequently deleted that Add code. The debugger quickly showed my problem.&#160; Rowans blog states: </p>

<blockquote>
  <p><em>Our team has been careful to ensure that all the operations available as Power Shell commands can be easily performed from your code.</em> </p>
</blockquote>

<p>It’s a good idea to run the command <strong>update-database</strong> multiple times to make sure it works each time (after the 1st run, it shouldn’t make any changes).</p>

<p>Follow me ( <a href="https://twitter.com/RickAndMSFT">@RickAndMSFT</a> )&#160;&#160; on twitter where I have a no spam guarantee of quality tweets.</p>]]></content:encoded>
    </item>
    <item>
      <title>Optimal Azure Restarts</title>
      <link>https://docs.microsoft.com/archive/blogs/rickandy/optimal-azure-restarts</link>
      <pubDate>Fri, 21 Dec 2012 20:55:40 GMT</pubDate>
      <dc:creator><![CDATA[Rick_Anderson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rickandy/2012/12/21/optimal-azure-restarts/</guid>
      <description><![CDATA[Restarts for Web Roles  Updated 17 Jan 2013:&#160; Tracing in OnStop is not supported.  An often...]]></description>
      <content:encoded><![CDATA[<h2>Restarts for Web Roles</h2>  <p><font style="background-color: rgb(255, 255, 0);">Updated 17 Jan 2013:&#160; Tracing in OnStop is not supported.</font></p>  <p>An often neglected consideration in Windows Azure is how to handle restarts. It’s important to handle restarts correctly, so you don’t lose data or corrupt your persisted data, and so you can quickly shutdown, restart, and efficiently handle new requests.&#160; Windows Azure Cloud Service applications are restarted approximately twice per month for operating system updates. (For more information on OS updates, see <a href="https://blogs.msdn.com/b/kwill/archive/2012/09/19/role-instance-restarts-due-to-os-upgrades.aspx">Role Instance Restarts Due to OS Upgrades</a>.) When a web application is going to be shutdown, the <a href="https://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.serviceruntime.roleenvironment.stopping.aspx">RoleEnvironment.Stopping</a> event is raised. The web role boilerplate created by Visual Studio does not override the <a href="https://technet.microsoft.com/en-us/subscriptions/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx">OnStop</a> method, so the application will have only a few seconds to finish processing HTTP requests before it is shut down. If your web role is busy with pending requests, some of these requests can be lost. You can delay the restarting or your web role by up to 5 minutes by overriding the <a href="https://technet.microsoft.com/en-us/subscriptions/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx">OnStop</a> method and calling Sleep, but that’s far from optimal. Once the <a href="https://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.serviceruntime.roleenvironment.stopping.aspx">Stopping</a> event is raised, the Load Balance (LB) stops sending requests to the web role, so delaying the restart for longer than it takes to process pending requests leaves your virtual machine spinning in Sleep, doing no useful work. The optimal approach is to wait in the <a href="https://technet.microsoft.com/en-us/subscriptions/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx">OnStop</a> method until there are no more requests, and then initiate the shutdown. The sooner you shutdown, the sooner the VM can restart and begin processing requests. To implement the optimal shutdown strategy, add the following code to your <a href="https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleentrypoint.aspx">WebRole</a> class.</p>  <pre class="code"><span style="background: white; color: blue;">public override void </span><span style="background: white; color: black;">OnStop()
{
    </span><span style="background: white; color: rgb(43, 145, 175);">Trace</span><span style="background: white; color: black;">.TraceInformation(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;OnStop called WebRole&quot;</span><span style="background: white; color: black;">);
    </span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">pcrc = </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">PerformanceCounter</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;ASP.NET&quot;</span><span style="background: white; color: black;">, </span><span style="background: white; color: rgb(163, 21, 21);">&quot;Requests Current&quot;</span><span style="background: white; color: black;">, </span><span style="background: white; color: rgb(163, 21, 21);">&quot;&quot;</span><span style="background: white; color: black;">);

    </span><span style="background: white; color: blue;">while </span><span style="background: white; color: black;">(</span><span style="background: white; color: blue;">true</span><span style="background: white; color: black;">)
    {
        </span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">rc = pcrc.NextValue();
        </span><span style="background: white; color: rgb(43, 145, 175);">Trace</span><span style="background: white; color: black;">.TraceInformation(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;ASP.NET Requests Current = &quot; </span><span style="background: white; color: black;">+ rc.ToString());
        </span><span style="background: white; color: blue;">if </span><span style="background: white; color: black;">(rc &lt;= 0)
            </span><span style="background: white; color: blue;">break</span><span style="background: white; color: black;">; 
        System.Threading.</span><span style="background: white; color: rgb(43, 145, 175);">Thread</span><span style="background: white; color: black;">.Sleep(1000);
    }
}</span></pre>

<p>The code above checks the ASP.NET request’s current counter. As long as there are requests, the <a href="https://technet.microsoft.com/en-us/subscriptions/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx">OnStop</a> method calls Sleep to delay the shutdown. Once the current request’s counter drops to zero, <a href="https://technet.microsoft.com/en-us/subscriptions/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx">OnStop</a> returns, which initiates shutdown. Should the web server be so busy that the pending requests cannot be completed in 5 minutes, the application is shut down anyway. Remember that once the <a href="https://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.serviceruntime.roleenvironment.stopping.aspx">Stopping</a> event is raised, the LB stops sending requests to the web role, so unless you had a massively under sized (or too few instances of) web role, you should never need more than a few seconds to complete the current requests.</p>

<p>The code above writes Trace data, but unless you perform a tricky <a href="https://msdn.microsoft.com/en-us/library/windowsazure/gg433075.aspx">On-Demand Transfer</a>, the trace data from the <a href="https://technet.microsoft.com/en-us/subscriptions/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx">OnStop</a> method will never appear in <strong>WADLogsTable</strong>. Later in this blog I’ll show how you can use <a href="https://technet.microsoft.com/en-us/sysinternals/bb896647.aspx">DebugView</a> to see these trace events. I’ll also show how you can get tracing working in the web role <a href="https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleentrypoint.onstart.aspx">OnStart</a> method.</p>

<h3>Optimal Restarts for Worker Roles</h3>

<p>Handling the <a href="https://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.serviceruntime.roleenvironment.stopping.aspx">Stopping</a> event in a worker role requires a different approach. Typically the worker role processes queue messages in the <a href="https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleentrypoint.run.aspx">Run</a> method. The strategy involves two global variables; one to notify the <a href="https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleentrypoint.run.aspx">Run</a> method that the <a href="https://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.serviceruntime.roleenvironment.stopping.aspx">Stopping</a> event has been raised, and another global to notify the <a href="https://technet.microsoft.com/en-us/subscriptions/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx">OnStop</a> method that it’s safe to initiate shutdown. (Shutdown is initiated by returning from <a href="https://technet.microsoft.com/en-us/subscriptions/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx">OnStop</a>.) The following code demonstrates the two global approaches.</p>

<pre class="code"><span style="background: white; color: blue;">public class </span><span style="background: white; color: rgb(43, 145, 175);">WorkerRole </span><span style="background: white; color: black;">: </span><span style="background: white; color: rgb(43, 145, 175);">RoleEntryPoint
</span><span style="background: white; color: black;">{
    </span><span style="background: white; color: blue;">private </span><span style="background: white; color: rgb(43, 145, 175);">CloudQueue </span><span style="background: white; color: black;">myWorkQueue;
    </span><font style="background-color: rgb(255, 255, 0);"><span style="background: white; color: blue;">private <font style="background-color: rgb(255, 255, 0);">volatile</font> <font style="background-color: rgb(255, 255, 0);">bool</font> </span><span style="background: white; color: black;"><font style="background-color: rgb(255, 255, 0);">onStopCalled</font> = </span><span style="background: white; color: blue;">false</span><span style="background: white; color: black;"><font style="background-color: rgb(255, 255, 0);">;</font>
    </span><span style="background: white; color: blue;">private <font style="background-color: rgb(255, 255, 0);">volatile</font> <font style="background-color: rgb(255, 255, 0);">bool</font> </span><span style="background: white; color: black;"><font style="background-color: rgb(255, 255, 0);">returnedFromRunMethod</font> = </span><span style="background: white; color: blue;">false</span></font><span style="background: white; color: black;"><font style="background-color: rgb(255, 255, 0);">;</font>

    </span><span style="background: white; color: blue;">public override void </span><span style="background: white; color: black;">Run()
    {
        </span><span style="background: white; color: rgb(43, 145, 175);">CloudQueueMessage </span><span style="background: white; color: black;">msg = </span><span style="background: white; color: blue;">null</span><span style="background: white; color: black;">;
        </span><span style="background: white; color: blue;">while </span><span style="background: white; color: black;">(</span><span style="background: white; color: blue;">true</span><span style="background: white; color: black;">)
        {
            </span><span style="background: white; color: blue;">try
            </span><span style="background: white; color: black;">{
                </span><span style="background: white; color: green;">// If OnStop has been called, return to do a graceful shutdown.
                </span><span style="background: white; color: blue;">if </span><span style="background: white; color: black;">(<font style="background-color: rgb(255, 255, 0);">onStopCalled</font> == </span><span style="background: white; color: blue;"><font style="background-color: rgb(255, 255, 0);">true</font></span><span style="background: white; color: black;">)
                {
                    </span><span style="background: white; color: rgb(43, 145, 175);">Trace</span><span style="background: white; color: black;">.TraceInformation(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;onStopCalled WorkerRole&quot;</span><span style="background: white; color: black;">);
                    <font style="background-color: rgb(255, 255, 0);">returnedFromRunMethod</font> = </span><span style="background: white; color: blue;"><font style="background-color: rgb(255, 255, 0);">true</font></span><span style="background: white; color: black;">;
                    </span><span style="background: white; color: blue;"><font style="background-color: rgb(255, 255, 0);">return</font></span><span style="background: white; color: black;">;
                }
                </span><span style="background: white; color: green;">// Retrieve and process a new message.
                </span><span style="background: white; color: black;">msg = myWorkQueue.GetMessage();
                </span><span style="background: white; color: blue;">if </span><span style="background: white; color: black;">(msg != </span><span style="background: white; color: blue;">null</span><span style="background: white; color: black;">)
                {
                    ProcessQueueMessage(msg);
                }
                </span><span style="background: white; color: blue;">else
                </span><span style="background: white; color: black;">{
                    System.Threading.</span><span style="background: white; color: rgb(43, 145, 175);">Thread</span><span style="background: white; color: black;">.Sleep(1000);
</span><span style="background: white; color: black;">                }
            }
            </span><span style="background: white; color: blue;">catch </span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(43, 145, 175);">Exception </span><span style="background: white; color: black;">ex)
            {
                </span><span style="background: white; color: blue;">string </span><span style="background: white; color: black;">err = ex.Message;
                </span><span style="background: white; color: blue;">if </span><span style="background: white; color: black;">(ex.InnerException != </span><span style="background: white; color: blue;">null</span><span style="background: white; color: black;">)
                    err += </span><span style="background: white; color: rgb(163, 21, 21);">&quot; Inner Exception: &quot; </span><span style="background: white; color: black;">+ ex.InnerException.Message;
                </span><span style="background: white; color: rgb(43, 145, 175);">Trace</span><span style="background: white; color: black;">.TraceError(err);
                </span><span style="background: white; color: green;">// Don't fill up Trace storage if we have a bug in  process loop.
                </span><span style="background: white; color: black;">System.Threading.</span><span style="background: white; color: rgb(43, 145, 175);">Thread</span><span style="background: white; color: black;">.Sleep(1000);
            }
        }
    }

    </span><span style="background: white; color: blue;"><font style="background-color: rgb(255, 255, 0);">public override void </font></span><span style="background: white; color: black;"><font style="background-color: rgb(255, 255, 0);">OnStop()</font>
    {
        <font style="background-color: rgb(255, 255, 0);">onStopCalled = </font></span><span style="background: white; color: blue;"><font style="background-color: rgb(255, 255, 0);">true</font></span><span style="background: white; color: black;">;
        </span><span style="background: white; color: rgb(43, 145, 175);">Trace</span><span style="background: white; color: black;">.TraceInformation(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;OnStop called from Worker Role.&quot;</span><span style="background: white; color: black;">);
        </span><font style="background-color: rgb(255, 255, 0);"><span style="background: white; color: blue;"><font style="background-color: rgb(255, 255, 0);">while</font> </span><span style="background: white; color: black;">(<font style="background-color: rgb(255, 255, 0);">returnedFromRunMethod</font> <font style="background-color: rgb(255, 255, 0);">==</font> </span></font><font style="background-color: rgb(255, 255, 0);"><span style="background: white; color: blue;"><font style="background-color: rgb(255, 255, 0);">fals</font>e</span></font><span style="background: white; color: black;"><font style="background-color: rgb(255, 255, 0);">)</font>
        {
            </span><span style="background: white; color: rgb(43, 145, 175);">Trace</span><span style="background: white; color: black;">.TraceInformation(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;Waiting for returnedFromRunMethod&quot;</span><span style="background: white; color: black;">);
            <font style="background-color: rgb(255, 255, 0);">System.Threading.</font></span><span style="background: white; color: rgb(43, 145, 175);"><font style="background-color: rgb(255, 255, 0);">Thread</font></span><span style="background: white; color: black;"><font style="background-color: rgb(255, 255, 0);">.Sleep</font>(1000);
        }
        </span><font style="background-color: rgb(255, 255, 0);"><span style="background: white; color: rgb(43, 145, 175);"><font style="background-color: rgb(255, 255, 0);">Trace</font></span><span style="background: white; color: black;">.<font style="background-color: rgb(255, 255, 0);">TraceInformation</font>(</span></font><span style="background: white; color: rgb(163, 21, 21);"><font style="background-color: rgb(255, 255, 0);">&quot;returnedFromRunMethod is true, so restarting</font>&quot;</span><span style="background: white; color: black;">);
    <font style="background-color: rgb(255, 255, 0);">}</font>

    </span><span style="background: white; color: blue;">private void </span><span style="background: white; color: black;">ProcessQueueMessage(</span><span style="background: white; color: rgb(43, 145, 175);">CloudQueueMessage </span><span style="background: white; color: black;">msg)
    {
        </span><span style="background: white; color: green;">// Code omitted for clarity.
        </span><span style="background: white; color: black;">System.Threading.</span><span style="background: white; color: rgb(43, 145, 175);">Thread</span><span style="background: white; color: black;">.Sleep(1000);
    }

    </span><span style="background: white; color: blue;">private void </span><span style="background: white; color: black;">ConfigDiagnostics()
    {
        </span><span style="background: white; color: green;">// See <font style="background-color: rgb(255, 255, 0);"><strong>https://bit.ly/UXM44C</strong>
</font></span><span style="background: white; color: black;">    }

    </span><span style="background: white; color: blue;">public override bool </span><span style="background: white; color: black;">OnStart()
    {
        </span><span style="background: white; color: green;">// Code omitted for clarity.
</span><span style="background: white; color: black;">
    }
</span><span style="background: white; color: black;">}
</span></pre>

<p>When <a href="https://technet.microsoft.com/en-us/subscriptions/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx">OnStop</a> is called, the global <strong>onStopCalled</strong> is set to true, which signals the code in the <a href="https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleentrypoint.run.aspx">Run</a> method to shut down at the top of the loop, when no queue event is being processed.</p>

<h2>Viewing OnStop Trace Data</h2>

<p>As mentioned previously, unless you perform a tricky <a href="https://msdn.microsoft.com/en-us/library/windowsazure/gg433075.aspx">On-Demand Transfer</a>, the trace data from the <a href="https://technet.microsoft.com/en-us/subscriptions/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx">OnStop</a> method will never appear in <strong>WADLogsTable</strong>. We’ll use <a href="https://technet.microsoft.com/en-us/sysinternals/bb896647.aspx">Dbgview</a> to see these trace events. In Solution Explorer, right-click on the cloud project and select <strong>Publish</strong>.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/5100.selectPub_6BD18E24.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/5100.selectPub_5F00_6BD18E24.png"><img title="selectPub" style="display: inline; background-image: none;" border="0" alt="selectPub" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/2870.selectPub_thumb_74C12063.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/2870.selectPub_5F00_thumb_5F00_74C12063.png" width="271" height="286" /></a></p>

<p>Download your publish profile.&#160; In the <strong>Publish Windows Azure Application</strong> dialog box, select <strong>Debug</strong> and select <strong>Enable Remote Desktop</strong> for all roles.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/7002.PubSettings_3D7643A9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/7002.PubSettings_5F00_3D7643A9.png"><img title="PubSettings" style="display: inline; background-image: none;" border="0" alt="PubSettings" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/3617.PubSettings_thumb_518F6032.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/3617.PubSettings_5F00_thumb_5F00_518F6032.png" width="688" height="467" /></a></p>

<p>The compiler removes Trace calls from release builds, so you’ll need to set the build configuration to <strong>Debug</strong> to see the Trace data. Once the application is published and running, in Visual Studio, select <strong>Server Explorer</strong> (Ctl+Alt+S). Select <strong>Windows Azure Compute</strong>, and then select your cloud deployment. (In this case it’s called t6 and it’s a production deployment.) Select the web role instance, right-click, and select <strong>Connect using Remote Desktop</strong>.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/6661.serverExp_7B0A87A2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/6661.serverExp_5F00_7B0A87A2.png"><img title="serverExp" style="display: inline; background-image: none;" border="0" alt="serverExp" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/0211.serverExp_thumb_769406DB.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/0211.serverExp_5F00_thumb_5F00_769406DB.png" width="409" height="260" /></a></p>

<p>Remote Desktop Connection (RDC) will use the account name you specified in the publish wizard and prompt you for the password you entered. In the left side of the taskbar, select the <strong>Server Manager</strong> icon.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/1222.rdcSelectSvrMgr_0F23A42C.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/1222.rdcSelectSvrMgr_5F00_0F23A42C.png"><img title="rdcSelectSvrMgr" style="display: inline; background-image: none;" border="0" alt="rdcSelectSvrMgr" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/2451.rdcSelectSvrMgr_thumb_23A8F3AA.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/2451.rdcSelectSvrMgr_5F00_thumb_5F00_23A8F3AA.png" width="242" height="50" /></a></p>

<p>In the left tab of <strong>Server Manager</strong>, select <strong>Local Server</strong>, and then select <strong>IE Enhanced Security Configuration</strong> (IE ESC). Select the off radio button in the IE ESC dialog box.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/2783.disableIE_5EFC5968.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/2783.disableIE_5F00_5EFC5968.png"><img title="disableIE" style="display: inline; background-image: none;" border="0" alt="disableIE" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/8750.disableIE_thumb_731575F1.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/8750.disableIE_5F00_thumb_5F00_731575F1.png" width="783" height="526" /></a></p>

<p>Start Internet Explorer, download and install <a href="https://technet.microsoft.com/en-us/sysinternals/bb896647.aspx">DebugView</a>. Start <a href="https://technet.microsoft.com/en-us/sysinternals/bb896647.aspx">DebugView</a>, and in the <strong>Capture</strong> menu, select <strong>Capture Global Win32</strong>.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/5861.dbgCapture_05479A70.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/5861.dbgCapture_5F00_05479A70.png"><img title="dbgCapture" style="display: inline; background-image: none;" border="0" alt="dbgCapture" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/1072.dbgCapture_thumb_7292A0B8.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/1072.dbgCapture_5F00_thumb_5F00_7292A0B8.png" width="505" height="307" /></a></p>

<p>Select the filter icon, and then enter the following exclude filter:</p>

<p><font face="Lucida Console">Heartbeat;*is reporting state Ready.;*has current state Started*;*WaIISHost.exe Information:*;*Microsoft.WindowsAzure.ServiceRuntime Information:*;*Invalid parameter passed *;*w3wp.exe Information:*;</font> </p>

<p>&#160;</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/7026.dbgFilter_350542EF.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/7026.dbgFilter_5F00_350542EF.png"><img title="dbgFilter" style="display: inline; background-image: none;" border="0" alt="dbgFilter" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/0167.dbgFilter_thumb_34990FFA.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/0167.dbgFilter_5F00_thumb_5F00_34990FFA.png" width="505" height="323" /></a></p>

<p>For this test, I added the <a href="https://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.serviceruntime.roleenvironment.requestrecycle.aspx">RoleEnvironment.RequestRecycle</a>&#160; method to the <strong>About</strong> action method, which as the name suggests, initiates the shutdown/restart sequence. Alternatively, you can publish the application again, which will also initiate the shutdown/restart sequence.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/0552.dbgOnStop_45F9A2F3.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/0552.dbgOnStop_5F00_45F9A2F3.png"><img title="dbgOnStop" style="display: inline; background-image: none;" border="0" alt="dbgOnStop" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/0167.dbgOnStop_thumb_365997E2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/0167.dbgOnStop_5F00_thumb_5F00_365997E2.png" width="614" height="297" /></a></p>

<p>&#160;</p>

<p>Follow the same procedure to view the trace data in the worker role VM. Select the worker role instance, right-click and select <strong>Connect using Remote Desktop</strong>.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/8802.workerRoleRDC_023B91F1.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/8802.workerRoleRDC_5F00_023B91F1.png"><img title="workerRoleRDC" style="display: inline; background-image: none;" border="0" alt="workerRoleRDC" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/0385.workerRoleRDC_thumb_2FBCB1B4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/0385.workerRoleRDC_5F00_thumb_5F00_2FBCB1B4.png" width="341" height="299" /></a></p>

<p>Follow the procedure above to disable <strong>IE Enhanced Security Configuration</strong>. Install and configure <a href="https://technet.microsoft.com/en-us/sysinternals/bb896647.aspx">DebugView</a> using the instructions above. I use the following filter for worker roles:</p>

<p><font face="Lucida Console">Heartbeat;*is reporting state Ready.;*has current state Started, desired *;*w3wp.exe Information: *;*WaWorkerHost.exe Information*;*Invalid parameter passed *;*Microsoft.WindowsAzure.ServiceRuntime Information:*;</font></p>

<p>For this sample, I published the Azure package, which causes the shutdown/restart procedure.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/4263.dbgViewWorker_2F507EBF.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/4263.dbgViewWorker_5F00_2F507EBF.png"><img title="dbgViewWorker" style="display: inline; background-image: none;" border="0" alt="dbgViewWorker" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/6735.dbgViewWorker_thumb_1FB073AE.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/6735.dbgViewWorker_5F00_thumb_5F00_1FB073AE.png" width="594" height="271" /></a> 

  <br /></p>

<p>One last departing tip: To get tracing working in the web roles <strong>OnStart</strong> method, add the following:</p>

<pre class="code"><span style="background: white; color: rgb(43, 145, 175);">Trace</span><span style="background: white; color: black;">.Listeners.Add(<br /></span><span style="background: white; color: black;">   </span><span style="background: white; color: blue;">new </span><span style="background: white; color: black;">Microsoft.WindowsAzure.Diagnostics.</span><span style="background: white; color: rgb(43, 145, 175);">DiagnosticMonitorTraceListener</span><span style="background: white; color: black;">());</span></pre>

<h3>Tracing in OnStop</h3>

<p>Tracing in the <a href="https://technet.microsoft.com/en-us/subscriptions/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx">OnStop</a> method is not supported and not recommended for the following reasons:</p>

<ol>
  <li>The <a href="https://technet.microsoft.com/en-us/subscriptions/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx">OnStop</a> method should be used only to delay shutdown until you’ve processed all pending requests (web role) or completed a unit of work (worker role) so you get a clean shutdown. As stated above, you should return from OnStop (which initiates shutdown) as soon as possible, as soon as you can get your application in a clean shut down state. The <a href="https://technet.microsoft.com/en-us/subscriptions/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx">OnStop</a> method should be very simple, so you shouldn’t need to trace in this method.</li>

  <li><a href="https://technet.microsoft.com/en-us/subscriptions/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx">OnStop</a> is called from a different process which doesn’t read the trace listener configuration in the <em>app.config</em> (worker role) or <em>web.config</em> (web role) file. To get it working you’d have to configure the azure diagnostics trace listener programmatically to hook up the listener to the agent process that manages the PaaS VM role. </li>

  <li> There are inherent polling wait times during <a href="https://msdn.microsoft.com/en-us/library/windowsazure/gg433075.aspx" target="_blank">On-demand transfer</a> of a minute or more.&#160; It is not well suited for execution during the time limited OnStop.</li>
</ol>

<p>Most of the information in this blog comes from <a href="https://www.windowsazure.com/en-us/develop/net/tutorials/multi-tier-web-site/1-overview/">Azure multi-tier tutorial</a> Tom and I published last week. Be sure to check it out for lots of other good tips. </p>

<p>Follow me ( <a href="https://twitter.com/RickAndMSFT" target="_blank">@RickAndMSFT</a> )&#160;&#160; on twitter where I have a no spam guarantee of quality tweets.</p>]]></content:encoded>
    </item>
    <item>
      <title>Top Azure Tips and Best Practices</title>
      <link>https://docs.microsoft.com/archive/blogs/rickandy/top-azure-tips-and-best-practices</link>
      <pubDate>Thu, 20 Dec 2012 12:56:08 GMT</pubDate>
      <dc:creator><![CDATA[Rick_Anderson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rickandy/2012/12/20/top-azure-tips-and-best-practices/</guid>
      <description><![CDATA[Tom Dykstra and I have just published an Azure multi-tier tutorial with the complete source. It has...]]></description>
      <content:encoded><![CDATA[<p>Tom Dykstra and I have just published an <a href="https://www.windowsazure.com/en-us/develop/net/tutorials/multi-tier-web-site/1-overview/">Azure multi-tier tutorial</a> with the complete source. It has many valuable programming tips and best practices you can&rsquo;t find anywhere else. Learn how to use Windows Azure Storage tables, queues, and blobs in a multi-tier application that has ASP.NET MVC 4 and ASP.NET Web API on the front end. My favorite sections include:<ul>   <li> Web sites versus web role in a cloud service. </li>    <li> How to design tables for efficient queries using the new Windows Azure Storage Client Library (SCL) 2.0. The new SCL offers huge performance benefits over the previous SCL.</li>    <li>How to handle concurrency exceptions in ASP.NET MVC using the SCL. There are a couple tricks to getting it right, but the sample shows it&rsquo;s easy once you know these. </li>    <li> How to set the retry policy in SCL 2.0 code for a UI. The SCL 2.0 API automatically retries three times with exponentially increasing timeout limits, something you generally don&rsquo;t want to do in a web page.</li>    <li>How to use batch deletes and batch queue fetches to save transaction costs.</li>    <li>Using nullable types on storage tables containing multiple types (and why it&rsquo;s important).</li>    <li>How to optimally shut down web and worker roles. Windows Azure Cloud Service applications are restarted approximately twice per month for operating system updates. When a web application is going to be shut down, an OnStop event is raised. The web role boilerplate created by Visual Studio does not override the OnStop method, so the application will have only a few seconds to finish processing HTTP requests before it is shut down. </li>    <li>How to write effective OnStart methods. The boilerplate code generated by Visual Studio for the OnStart method uses several obsolete calls such as:</li>    <ul>     <li>       <div align="left">Trace.WriteLine("Working", "Information");</div>     </li>      <li>       <div align="left">ServicePointManager.DefaultConnectionLimit = 12;</div>     </li>   </ul>    <li>How to effectively use tracing and diagnostics. </li>    <li>Tips on cost savings.</li>    <li> Why you should care about affinity. (Currently affinity requires you to navigate to the old portal.)</li>    <li>Using GUIDs versus Time.Now.Ticks for row keys.</li>    <li>How to decrease project startup time by disabling the Azure Storage Emulator. </li> </ul></p>
]]></content:encoded>
    </item>
    <item>
      <title>Debugging Azure HTTP 500 Errors</title>
      <link>https://docs.microsoft.com/archive/blogs/rickandy/debugging-azure-http-500-errors</link>
      <pubDate>Tue, 06 Nov 2012 15:25:26 GMT</pubDate>
      <dc:creator><![CDATA[Rick_Anderson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rickandy/2012/11/06/debugging-azure-http-500-errors/</guid>
      <description><![CDATA[By default, Windows Azure Cloud Services Web Role applications, running in Windows Azure or the...]]></description>
      <content:encoded><![CDATA[<p>By default, Windows Azure Cloud Services Web Role applications, running in Windows Azure or the compute emulator, have the&nbsp; <a href="https://www.iis.net/configreference/system.webserver/httperrors">HTTP Errors &lt;httpErrors&gt;</a> element of the <em>ApplicationHost.config</em> file set to not display detailed error information. What surprised me is that under the compute emulator, IIS-Express doesn&rsquo;t use the <em>C:Users&lt;user&gt;DocumentsIISExpressconfigapplicationhost.config</em> file, it uses a an <em>ApplicationHost.config</em> file pointed to by the <strong>%APPCMD%</strong> environment variable.<p>To get detailed error messages on Azure or the compute emulator, you need to add a startup command to your project with the following lines.</p><p><font face="Lucida Console">%windir%system32inetsrvAppCmd.exe set config -section:system.webServer/httpErrors -errorMode:Detailed     <br> %APPCMD% set config -section:system.webServer/httpErrors -errorMode:Detailed</font> </p><p>The first line enables detailed error messages on Azure. The second line enables them on the compute emulator.</p><p>Follow the instructions at <a href="https://msdn.microsoft.com/en-us/library/windowsazure/jj154098.aspx">How to Block Specific IP Addresses from Accessing a Web Role</a> for setting up the startup command, but replace the <strong>ipSecurity</strong> line with the lines above.</p><p><em>In addition to blogging, I use Twitter to make quick posts and share links. My Twitter handle is</em>: <a href="https://twitter.com/RickAndMSFT">@RickAndMSFT</a></p></p>
]]></content:encoded>
    </item>
    <item>
      <title>Debugging HTTP 500 - Internal server error with the Windows Azure SDK</title>
      <link>https://docs.microsoft.com/archive/blogs/rickandy/debugging-http-500-internal-server-error-with-the-windows-azure-sdk</link>
      <pubDate>Thu, 25 Oct 2012 17:25:57 GMT</pubDate>
      <dc:creator><![CDATA[Rick_Anderson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rickandy/2012/10/25/debugging-http-500-internal-server-error-with-the-windows-azure-sdk/</guid>
      <description><![CDATA[Update November 2012 – See my new blog entry Debugging Azure HTTP 500 Errors. This blog no longer...]]></description>
      <content:encoded><![CDATA[<p>Update November 2012 – See my new blog entry <a href="https://blogs.msdn.com/b/rickandy/archive/2012/11/06/debugging-azure-http-500-errors.aspx">Debugging Azure HTTP 500 Errors</a>. This blog no longer applies to Azure.</p>  <p>Using the current Azure SDK and Visual Studio 2012, you may get a HTTP 500 internal error if there is something wrong with your Web.config file.</p>  <p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/2570.clip_image002_6834276E.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/2570.clip_5F00_image002_5F00_6834276E.jpg" /></p>  <p>OK, something went wrong, but what? I actually hit this error last year and <a href="https://blogs.msdn.com/b/rickandy/archive/2011/11/23/debugging-http-500-internal-server-error-with-windows-azure-sdk.aspx">blogged the solution</a> – but a lot of changes have taken place with the Azure SDK since then, and last years solution no longer works.</p>  <p>By default, the <em>ApplicationHost.config</em> file does not enable detailed error messages. The solution I blogged last year was to edit this file and update the <em>&lt;httpErrors&gt;</em>&#160; element and add errorMode=&quot;Detailed&quot;. But that solution no longer works. Previously the Azure compute emulator used IIS, so you could edit <em>%windir%\System32\inetsrv\config\ApplicationHost.config</em> and add detailed errors.&#160; Now the Azure compute emulator uses IIS Express. Given that IIS Express by default uses stores the <em>applicationhost.config</em>&#160; file in <em>C:\Users\&lt;user&gt;\Documents\IISExpress\config ,&#160; </em>I naturally tried to update that file. It turns out that under the Azure compute emulator, IIS Express uses the <em>applicationhost.config</em>&#160; file in a directory exposed with the %APPCMD% environment variable. </p>]]></content:encoded>
    </item>
    <item>
      <title>Azure Table Storage</title>
      <link>https://docs.microsoft.com/archive/blogs/rickandy/azure-table-storage</link>
      <pubDate>Thu, 20 Sep 2012 18:11:00 GMT</pubDate>
      <dc:creator><![CDATA[Rick_Anderson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rickandy/2012/09/20/azure-table-storage/</guid>
      <description><![CDATA[This Azure Table Storage tutorial/sample/walkthrough will get you using Azure Table Storage from...]]></description>
      <content:encoded><![CDATA[<p>This Azure Table Storage tutorial/sample/walkthrough will get you using Azure Table Storage from ASP.NET MVC in 15 minutes. <a href="https://blogs.msdn.com/337758/ProfileUrlRedirect.ashx">Tom Dykstra</a> (of <a href="https://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application">MVC/EF fame</a>) and I are working on an Azure email service sample application. All the code was written by Tom.&nbsp;</p>
<p>Our first step was creating a Azure Table Storage account to contain the email distribution lists. This post contains the essential steps to get Azure Table Storage working with an ASP.NET application.&nbsp; You must first have an Azure account &ndash; you can get one free <a href="https://www.windowsazure.com/en-us/pricing/free-trial/?WT.mc_id=azurebg_us_sem_branded_trialpage">here</a>.</p>
<h3>Create a Windows Azure Storage account</h3>
<ol>
<li>Log into the <a href="https://manage.windowsazure.com/">Windows Azure Management Portal</a>.</li>
<li>At the bottom of the navigation pane, click <strong>Storage</strong>, then click <strong>New</strong>. <br /> <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/0412.NewStorage_5D87F156.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/0412.NewStorage_5F00_5D87F156.png"><img title="NewStorage" style="display: inline; background-image: none;" border="0" alt="NewStorage" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/8816.NewStorage_thumb_0F7F91E1.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/8816.NewStorage_5F00_thumb_5F00_0F7F91E1.png" width="251" height="526" /></a> </li>
<li>Click <strong>QUICK CREATE</strong>. <br /> <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/1072.QuickCreate_5668B4DE.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/1072.QuickCreate_5F00_5668B4DE.png"><img title="QuickCreate" style="display: inline; background-image: none;" border="0" alt="QuickCreate" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/2148.QuickCreate_thumb_6F648523.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/2148.QuickCreate_5F00_thumb_5F00_6F648523.png" width="631" height="466" /></a> </li>
<li>Enter a subdomain name in the URL box at the top. In this screen shot I&rsquo;ve entered 012, so that magic string is taken and you&rsquo;ll need to enter something unique.&nbsp; Set the Region/Affinity group to your region. Disable Geo-Replication for this sample.</li>
<li>Click <strong>CREATE STORAGE ACCOUNT</strong>. The storage status page is displayed. It will take about a minute to create your storage account. The image below shows my status page. <br /> <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/7838.status_643AFAD9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/7838.status_5F00_643AFAD9.png"><img title="status" style="display: inline; background-image: none;" border="0" alt="status" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/7433.status_thumb_7D36CB1E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/7433.status_5F00_thumb_5F00_7D36CB1E.png" width="472" height="231" /></a> </li>
<li>Select the storage account you just created. On the bottom of the page, select <strong>MANAGE KEYS</strong>. <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/8400.ManageKeys_16329B64.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/8400.ManageKeys_5F00_16329B64.png"><img title="ManageKeys" style="display: inline; background-image: none;" border="0" alt="ManageKeys" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/1565.ManageKeys_thumb_5D1BBE61.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/1565.ManageKeys_5F00_thumb_5F00_5D1BBE61.png" width="102" height="66" /></a> <br />The image below shows my keys for account 012. Hackers take note, the keys are no good, I regenerated them right after taking this screenshot. <br /> <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/6355.Keys_2404E15F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/6355.Keys_5F00_2404E15F.png"><img title="Keys" style="display: inline; background-image: none;" border="0" alt="Keys" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/3716.Keys_thumb_=B1A4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/3716.Keys_5F00_thumb_5F00_3D00B1A4.png" width="502" height="435" /></a> <br /> <br />You&rsquo;ll need the storage account name and one of the keys later in this post.</li>
</ol>
<p>&nbsp;</p>
<h3>Install Azure Storage Explorer</h3>
<p>You can get Azure Storage Explorer <a href="https://azurestorageexplorer.codeplex.com/">here</a>. Alternatively, you can use <a href="https://www.cloudberrylab.com/free-microsoft-azure-explorer.aspx">CloudBerry</a>.</p>
<ol>
<li>Start Azure Storage Explorer. Select <strong>Add Account</strong>.</li>
<li>Copy your storage account name and access key, then click <strong>Add Storage Account</strong>. <br /> <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/6443.AzureStorageExp_7CCA9829.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/6443.AzureStorageExp_5F00_7CCA9829.png"><img title="AzureStorageExp" style="display: inline; background-image: none;" border="0" alt="AzureStorageExp" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/5466.AzureStorageExp_thumb_2398AE6A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/5466.AzureStorageExp_5F00_thumb_5F00_2398AE6A.png" width="658" height="587" /></a> </li>
<li>Click <strong>Tables</strong>, then click <strong>New</strong>. To use the code supplied with this post, name the table MailingList, then click <strong>Create Table</strong>. <br /> <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/3323.CreateTable_1C7971F2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/3323.CreateTable_5F00_1C7971F2.png"><img title="CreateTable" style="display: inline; background-image: none;" border="0" alt="CreateTable" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/4621.CreateTable_thumb_2A4BB7ED.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/4621.CreateTable_5F00_thumb_5F00_2A4BB7ED.png" width="650" height="585" /></a> <br /> <br />You can go back to Azure Storage Explorer to see the data you insert in your application. </li>
</ol>
<h3>Open the ASP.NET MVC Application to use the Azure Table </h3>
<ol>
<li>Open the sample <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/5736.MvcAES.zip" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73/5736.MvcAES.zip">download</a>. Alternatively, you can create a new ASP.NET MVC Internet Application, accept all the defaults.</li>
<li>Edit the root web.config file and add the storage connection string. The name doesn&rsquo;t matter, our sample code uses &ldquo;StorageConnectionString&rdquo; for the name.
<pre class="code"><span style="background: white; color: blue;"> &lt;</span><span style="background: white; color: #a31515;">connectionStrings</span><span style="background: white; color: blue;">&gt; &lt;</span><span style="background: white; color: #a31515;">add </span><span style="background: white; color: red;">name</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">"</span><span style="background: white; color: blue;">StorageConnectionString</span><span style="background: white; color: black;">" </span><span style="background: white; color: red;">connectionString</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">"</span><span style="background: white; color: blue;">DefaultEndpointsProtocol=https; AccountName=012; AccountKey=psMemlbL0m+n6/9dKBogusKey+Zom8XWDPY+hIwLb5MnrVSubbY1+m3QlFLTWTIhRZJpeg==</span><span style="background: white; color: black;">" </span><span style="background: white; color: blue;">/&gt; &lt;/</span><span style="background: white; color: #a31515;">connectionStrings</span><span style="background: white; color: blue;">&gt;</span></pre>
</li>
<li>Run the application and enter a couple email List names. You can see the data in both the application and in Azure Storage Explorer. <br /> <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/2311.Contoso_1A5F098B.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/2311.Contoso_5F00_1A5F098B.png"><img title="Contoso" style="display: inline; background-image: none;" border="0" alt="Contoso" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/3872.Contoso_thumb_2C3B9D58.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/3872.Contoso_5F00_thumb_5F00_2C3B9D58.png" width="595" height="563" /></a> <br /> <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/4442.AzureStoreWIthData_0C20909B.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/4442.AzureStoreWIthData_5F00_0C20909B.png"><img title="AzureStoreWIthData" style="display: inline; background-image: none;" border="0" alt="AzureStoreWIthData" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/3487.AzureStoreWIthData_thumb_05015423.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/3487.AzureStoreWIthData_5F00_thumb_5F00_05015423.png" width="654" height="584" /></a></li>
</ol>
<p>That was pretty cool &ndash; we just ran our ASP.NET MVC application in IIS Express and created data in the cloud!</p>
<h3>Deploy the application to Azure</h3>
<ol>
<li>From the Azure Portal, click on <strong>WEB SITES</strong> then <strong>NEW</strong>. <br /> <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/8267.NewWebSite_0BB45DA6.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/8267.NewWebSite_5F00_0BB45DA6.png"><img title="NewWebSite" style="display: inline; background-image: none;" border="0" alt="NewWebSite" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/0654.NewWebSite_thumb_529D80A3.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/0654.NewWebSite_5F00_thumb_5F00_529D80A3.png" width="207" height="455" /></a> </li>
<li>Click <strong>QUICK CREATE</strong>, then enter a URL. Click on the Web Site you just created, then click <strong>Download publish profile</strong>. <br /> <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/5444.Download_6B9950E8.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/5444.Download_5F00_6B9950E8.png"><img title="Download" style="display: inline; background-image: none;" border="0" alt="Download" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/1234.Download_thumb_606FC69E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/1234.Download_5F00_thumb_5F00_606FC69E.png" width="221" height="311" /></a> </li>
<li>Save the publish profile, you will import it in the next step.</li>
<li>In Visual Studio, right click on the <strong>MvcAES</strong> project, and select <strong>Publish</strong>. <br /> <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/4466.RtClickPub_647A1470.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/4466.RtClickPub_5F00_647A1470.png"><img title="RtClickPub" style="display: inline; background-image: none;" border="0" alt="RtClickPub" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/0247.RtClickPub_thumb_59508A26.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/0247.RtClickPub_5F00_thumb_5F00_59508A26.png" width="514" height="220" /></a> </li>
<li>In the <strong>Publish Web</strong> dialog, select <strong>Import</strong>. <br /> <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/5037.Import_724C5A6B.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/5037.Import_5F00_724C5A6B.png"><img title="Import" style="display: inline; background-image: none;" border="0" alt="Import" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/1727.Import_thumb_39357D69.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/1727.Import_5F00_thumb_5F00_39357D69.png" width="722" height="564" /></a> </li>
<li>Navigate to the profile you just downloaded. I like to select <strong>Next</strong> and review the Connection and Settings entries.&nbsp; Select <strong>Publish</strong>. Visual Studio automatically launch your deployed Web Site in your favorite browser. </li>
</ol>
<p>You can see the data you entered from your desktop and you can edit the data from the cloud.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/6507.completedApp_001EA067.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/6507.completedApp_5F00_001EA067.png"><img title="completedApp" style="display: inline; background-image: none;" border="0" alt="completedApp" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/2388.completedApp_thumb_0428EE39.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/2388.completedApp_5F00_thumb_5F00_0428EE39.png" width="531" height="563" /></a> </p>
<p><em>In addition to blogging, I use Twitter to make quick posts and share links. My Twitter handle is</em>: <a href="https://twitter.com/RickAndMSFT">@RickAndMSFT</a></p>]]></content:encoded>
    </item>
    <item>
      <title>ASP.NET MVC 4 Mobile Caching Bug Fixed</title>
      <link>https://docs.microsoft.com/archive/blogs/rickandy/asp-net-mvc-4-mobile-caching-bug-fixed</link>
      <pubDate>Mon, 17 Sep 2012 17:27:01 GMT</pubDate>
      <dc:creator><![CDATA[Rick_Anderson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rickandy/2012/09/17/asp-net-mvc-4-mobile-caching-bug-fixed/</guid>
      <description><![CDATA[31 October&#160; 2012 Update: The ASP.NET Fall 2012 Update includes the Fixed DisplayModes NuGet...]]></description>
      <content:encoded><![CDATA[<p><font style="background-color: rgb(255, 255, 0);">31 October&#160; 2012 Update: The </font><a href="https://go.microsoft.com/fwlink/?LinkID=271322"><font style="background-color: rgb(255, 255, 0);">ASP.NET Fall 2012 Update</font></a><font style="background-color: rgb(255, 255, 0);"> includes the </font><a href="https://nuget.org/packages/Microsoft.AspNet.Mvc.FixedDisplayModes"><font style="background-color: rgb(255, 255, 0);">Fixed DisplayModes</font></a><font style="background-color: rgb(255, 255, 0);"> NuGet package in the new project templates.</font>&#160; You will still need to apply the <a href="https://nuget.org/packages/Microsoft.AspNet.Mvc.FixedDisplayModes">Fixed DisplayModes</a> NuGet package to projects created before you install the <a href="https://go.microsoft.com/fwlink/?LinkID=271322">ASP.NET Fall 2012 Update</a>.</p>  <p>The RC and RTM versions of <a href="https://www.asp.net/mvc">ASP.NET MVC 4</a> had a bug in the view caching mechanism that resulted in mobile views (and other views specified by inserting a new <a href="https://www.asp.net/mvc/tutorials/mvc-4/aspnet-mvc-4-mobile-features">DefaultDisplayMode</a>)&#160; returning the wrong view.&#160; Initially the correct mobile view would be returned, but when the mobile view expired from the cache (which has a sliding default of 15 minutes) and when the desktop view was still in the cache, a mobile request for the view would return the desktop view. This bug was reported as bug number <a href="https://aspnetwebstack.codeplex.com/workitem/280">280 on CodePlex</a> and in the ASP.NET MVC forum <a href="https://forums.asp.net/t/1824033.aspx">here</a>.</p>  <p>Most applications that hit this problem can simply install the <a href="https://nuget.org/packages/Microsoft.AspNet.Mvc.FixedDisplayModes">Fixed DisplayModes</a> NuGet package. The <a href="https://go.microsoft.com/fwlink/?LinkID=271322">ASP.NET Fall 2012 Update</a> includes the <a href="https://nuget.org/packages/Microsoft.AspNet.Mvc.FixedDisplayModes">Fixed DisplayModes</a> NuGet package in the new project templates. </p>  <p>Applications that customize the collection of registered view engines will need to reference the fixed razor or fixed web forms view engine:</p>  <ul>   <li>Microsoft.Web.Mvc.FixedRazorViewEngine</li>    <li>Microsoft.Web.Mvc.FixedWebFormViewEngine</li> </ul>  <p>Applications that remove all the view engines, then add back Razor with the following code:</p>  <pre class="code"><span style="background: white; color: rgb(43, 145, 175);">ViewEngines</span><span style="background: white; color: black;">.Engines.Clear();
</span><span style="background: white; color: rgb(43, 145, 175);">ViewEngines</span><span style="background: white; color: black;">.Engines.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">RazorViewEngine</span><span style="background: white; color: black;">());</span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<p>Will need to replace the above code with the following:</p>

<pre class="code"><span style="background: white; color: rgb(43, 145, 175);">ViewEngines</span><span style="background: white; color: black;">.Engines.Clear();
</span><span style="background: white; color: rgb(43, 145, 175);">ViewEngines</span><span style="background: white; color: black;">.Engines.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: black;">Microsoft.Web.Mvc.FixedRazorViewEngine());</span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<p><em>In addition to blogging, I use Twitter to make quick posts and share links. My Twitter handle is</em>: <a href="https://twitter.com/RickAndMSFT">@RickAndMSFT</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Adding Web Optimization to a Web Pages Site</title>
      <link>https://docs.microsoft.com/archive/blogs/rickandy/adding-web-optimization-to-a-web-pages-site</link>
      <pubDate>Wed, 15 Aug 2012 18:56:07 GMT</pubDate>
      <dc:creator><![CDATA[Rick_Anderson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rickandy/2012/08/15/adding-web-optimization-to-a-web-pages-site/</guid>
      <description><![CDATA[Adding bundling and minification (B/M) in a Web Pages site follows the same formula ASP.NET MVC and...]]></description>
      <content:encoded><![CDATA[<p>Adding <a href="https://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification" target="_blank">bundling and minification</a> (B/M) in a Web Pages site follows the same formula ASP.NET MVC and Web Forms use:</p>  <ol>   <li>Declare and register bundles.</li>    <li>Consume bundles from within your views.&#160; </li> </ol>  <p>This blog entry describes the basics of using B/M in a Web Page site. For an overview and more details on B/M, see my tutorial <a href="https://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification" target="_blank">Bundling and Minification</a>. You can read about B/M for ASP.NET MVC <a href="https://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification" target="_blank">here</a> and for Web Forms <a href="https://blogs.msdn.com/b/rickandy/archive/2012/08/14/adding-bundling-and-minification-to-web-forms.aspx" target="_blank">here</a>.</p>  <p>To get started, we’ll create a new Web Pages site.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/6332.WP_6708B068.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/6332.WP_5F00_6708B068.png"><img style="display: inline; background-image: none;" title="WP" border="0" alt="WP" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/4278.WP_thumb_5FE973F0.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/4278.WP_5F00_thumb_5F00_5FE973F0.png" width="814" height="523" /></a></p>  <p>Open the <em>_AppStart.cshtml</em> file.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/3683.as_3FCE6733.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/3683.as_5F00_3FCE6733.png"><img style="display: inline; background-image: none;" title="as" border="0" alt="as" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/1538.as_thumb_71C607BD.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/1538.as_5F00_thumb_5F00_71C607BD.png" width="301" height="376" /></a></p>  <p>Replace the contents with the following code:</p>  <pre class="code"><span style="background: white; color: black;">@</span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">System.Web.Optimization;

</span><span style="background: white; color: black;">@{
</span><span style="background: white; color: black;">     </span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">bundles = </span><span style="background: white; color: rgb(43, 145, 175);">BundleTable</span><span style="background: white; color: black;">.Bundles;
     
 <mark>    bundles.UseCdn = </mark>  </span><span style="background: yellow; color: blue;">true</span><span style="background: yellow; color: black;">;   </span><span style="background: white; color: green;">//enable CDN support

    //add link to jquery on the CDN
    </span><span style="background: yellow; color: blue;">var </span><span style="background: white; color: black;">jqueryCdnPath = </span><span style="background: yellow; color: rgb(163, 21, 21);">&quot;https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js&quot;</span><span style="background: white; color: black;">;

    bundles.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">ScriptBundle</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/jquery&quot;</span><span style="background: white; color: black;">, 
                jqueryCdnPath).Include(
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/jquery-{version}.js&quot;</span><span style="background: white; color: black;">));

    bundles.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">ScriptBundle</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/jqueryui&quot;</span><span style="background: white; color: black;">).Include(
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/jquery-ui-{version}.js&quot;</span><span style="background: white; color: black;">));

    bundles.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">ScriptBundle</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/jqueryval&quot;</span><span style="background: white; color: black;">).Include(
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/jquery.unobtrusive*&quot;</span><span style="background: white; color: black;">,
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/jquery.validate*&quot;</span><span style="background: white; color: black;">));

    bundles.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">ScriptBundle</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/modernizr&quot;</span><span style="background: white; color: black;">).Include(
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/modernizr-*&quot;</span><span style="background: white; color: black;">));

    bundles.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">StyleBundle</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/css&quot;</span><span style="background: white; color: black;">).Include(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/site.css&quot;</span><span style="background: white; color: black;">));

    bundles.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">StyleBundle</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/themes/base/css&quot;</span><span style="background: white; color: black;">).Include(
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/themes/base/jquery.ui.core.css&quot;</span><span style="background: white; color: black;">,
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/themes/base/jquery.ui.resizable.css&quot;</span><span style="background: white; color: black;">,
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/themes/base/jquery.ui.selectable.css&quot;</span><span style="background: white; color: black;">,
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/themes/base/jquery.ui.accordion.css&quot;</span><span style="background: white; color: black;">,
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/themes/base/jquery.ui.autocomplete.css&quot;</span><span style="background: white; color: black;">,
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/themes/base/jquery.ui.button.css&quot;</span><span style="background: white; color: black;">,
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/themes/base/jquery.ui.dialog.css&quot;</span><span style="background: white; color: black;">,
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/themes/base/jquery.ui.slider.css&quot;</span><span style="background: white; color: black;">,
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/themes/base/jquery.ui.tabs.css&quot;</span><span style="background: white; color: black;">,
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/themes/base/jquery.ui.datepicker.css&quot;</span><span style="background: white; color: black;">,
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/themes/base/jquery.ui.progressbar.css&quot;</span><span style="background: white; color: black;">,
                </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/themes/base/jquery.ui.theme.css&quot;</span><span style="background: white; color: black;">));

</span><span style="background: yellow; color: black;">}</span></pre>

<pre class="code">New to the optimization framework for .Net 4.5 RTM is <a href="https://blogs.msdn.com/b/rickandy/archive/2011/05/21/using-cdns-to-improve-web-site-performance.aspx" target="_blank">CDN</a> support (shown in the yellow highlighted code above).</pre>

<h3>Consuming the Bundles</h3>

<p>Open the layout file and replace the script&#160; and CSS link tags in the &lt;head&gt; element with bundle references.&#160; The original code is shown below:</p>

<pre class="code"><span style="background: white; color: blue;">&lt;!</span><span style="background: white; color: maroon;">DOCTYPE </span><span style="background: white; color: red;">html</span><span style="background: white; color: blue;">&gt;
&lt;</span><span style="background: white; color: maroon;">html </span><span style="background: white; color: red;">lang</span><span style="background: white; color: blue;">=&quot;en&quot;&gt;
    &lt;</span><span style="background: white; color: maroon;">head</span><span style="background: white; color: blue;">&gt;
        &lt;</span><span style="background: white; color: maroon;">meta </span><span style="background: white; color: red;">charset</span><span style="background: white; color: blue;">=&quot;utf-8&quot; /&gt;
        &lt;</span><span style="background: white; color: maroon;">title</span><span style="background: white; color: blue;">&gt;</span><span style="background: yellow; color: black;">@</span><span style="background: white; color: black;">Page.Title - My ASP.NET Web Page</span><span style="background: white; color: blue;">&lt;/</span><span style="background: white; color: maroon;">title</span><span style="background: white; color: blue;">&gt;
        &lt;</span><span style="background: white; color: maroon;">link </span><span style="background: white; color: red;">href</span><span style="background: white; color: blue;">=&quot;~/Content/themes/base/jquery.ui.all.css&quot; </span><span style="background: white; color: red;">rel</span><span style="background: white; color: blue;">=&quot;stylesheet&quot; </span><span style="background: white; color: red;">type</span><span style="background: white; color: blue;">=&quot;text/css&quot; /&gt;
        &lt;</span><span style="background: white; color: maroon;">link </span><span style="background: white; color: red;">href</span><span style="background: white; color: blue;">=&quot;~/Content/Site.css&quot; </span><span style="background: white; color: red;">rel</span><span style="background: white; color: blue;">=&quot;stylesheet&quot; </span><span style="background: white; color: red;">type</span><span style="background: white; color: blue;">=&quot;text/css&quot; /&gt;
        &lt;</span><span style="background: white; color: maroon;">link </span><span style="background: white; color: red;">href</span><span style="background: white; color: blue;">=&quot;~/favicon.ico&quot; </span><span style="background: white; color: red;">rel</span><span style="background: white; color: blue;">=&quot;shortcut icon&quot; </span><span style="background: white; color: red;">type</span><span style="background: white; color: blue;">=&quot;image/x-icon&quot; /&gt;
        &lt;</span><span style="background: white; color: maroon;">script </span><span style="background: white; color: red;">src</span><span style="background: white; color: blue;">=&quot;~/Scripts/jquery-1.7.1.min.js&quot;&gt;&lt;/</span><span style="background: white; color: maroon;">script</span><span style="background: white; color: blue;">&gt;
        &lt;</span><span style="background: white; color: maroon;">script </span><span style="background: white; color: red;">src</span><span style="background: white; color: blue;">=&quot;~/Scripts/jquery-ui-1.8.20.js&quot;&gt;&lt;/</span><span style="background: white; color: maroon;">script</span><span style="background: white; color: blue;">&gt;
        &lt;</span><span style="background: white; color: maroon;">script </span><span style="background: white; color: red;">src</span><span style="background: white; color: blue;">=&quot;~/Scripts/modernizr-2.5.3.js&quot;&gt;&lt;/</span><span style="background: white; color: maroon;">script</span><span style="background: white; color: blue;">&gt;
        &lt;</span><span style="background: white; color: maroon;">meta </span><span style="background: white; color: red;">name</span><span style="background: white; color: blue;">=&quot;viewport&quot; </span><span style="background: white; color: red;">content</span><span style="background: white; color: blue;">=&quot;width=device-width&quot; /&gt;
    &lt;/</span><span style="background: white; color: maroon;">head</span><span style="background: white; color: blue;">&gt;</span></pre>

<p>The updated code is shown below.</p>

<pre class="code"><span style="background: yellow; color: black;">@</span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">System.Web.Optimization;
</span><span style="background: white; color: blue;">&lt;!</span><span style="background: white; color: maroon;">DOCTYPE </span><span style="background: white; color: red;">html</span><span style="background: white; color: blue;">&gt;
&lt;</span><span style="background: white; color: maroon;">html </span><span style="background: white; color: red;">lang</span><span style="background: white; color: blue;">=&quot;en&quot;&gt;
    &lt;</span><span style="background: white; color: maroon;">head</span><span style="background: white; color: blue;">&gt;
        &lt;</span><span style="background: white; color: maroon;">meta </span><span style="background: white; color: red;">charset</span><span style="background: white; color: blue;">=&quot;utf-8&quot; /&gt;
        &lt;</span><span style="background: white; color: maroon;">title</span><span style="background: white; color: blue;">&gt;</span><span style="background: yellow; color: black;">@</span><span style="background: white; color: black;">Page.Title - My ASP.NET Web Page</span><span style="background: white; color: blue;">&lt;/</span><span style="background: white; color: maroon;">title</span><span style="background: white; color: blue;">&gt;

         </span><span style="background: yellow; color: black;">@</span><span style="background: white; color: rgb(43, 145, 175);">Styles</span><span style="background: white; color: black;">.Render(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/themes/base/css&quot;</span><span style="background: white; color: black;">, </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/css&quot;</span><span style="background: white; color: black;">);

        </span><span style="background: white; color: blue;">&lt;</span><span style="background: white; color: maroon;">link </span><span style="background: white; color: red;">href</span><span style="background: white; color: blue;">=&quot;~/favicon.ico&quot; </span><span style="background: white; color: red;">rel</span><span style="background: white; color: blue;">=&quot;shortcut icon&quot; </span><span style="background: white; color: red;">type</span><span style="background: white; color: blue;">=&quot;image/x-icon&quot; /&gt;

        </span><span style="background: yellow; color: black;">@</span><span style="background: white; color: rgb(43, 145, 175);">Scripts</span><span style="background: white; color: black;">.Render(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/jquery&quot;</span><span style="background: white; color: black;">,
            </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/jqueryui&quot;</span><span style="background: white; color: black;">,
                     </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/modernizr&quot;</span><span style="background: white; color: black;">);

        </span><span style="background: white; color: blue;">&lt;</span><span style="background: white; color: maroon;">meta </span><span style="background: white; color: red;">name</span><span style="background: white; color: blue;">=&quot;viewport&quot; </span><span style="background: white; color: red;">content</span><span style="background: white; color: blue;">=&quot;width=device-width&quot; /&gt;
    &lt;/</span><span style="background: white; color: maroon;">head</span><span style="background: white; color: blue;">&gt;</span></pre>

<p>With the changes, the CSS and JavaScript can be delivered in bundles. Bundles are referenced in views using the Render method ,&#160; ( Styles.Render for CSS and Scripts.Render for JavaScript). </p>

<p>The default configuration for Web Pages sets the <a href="https://msdn.microsoft.com/en-us/library/s10awwz0.aspx" target="_blank">compilation element</a> to debug=true. When the compilation is debug=true, no bundling or minification occurs. Open the Web.config file and change the compilation elements debug attribute to false as shown below:</p>

<pre class="code"><span style="background: white; color: blue;">&lt;?</span><span style="background: white; color: rgb(163, 21, 21);">xml </span><span style="background: white; color: red;">version</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">1.0</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: red;">encoding</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">utf-8</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">?&gt;
&lt;</span><span style="background: white; color: rgb(163, 21, 21);">configuration</span><span style="background: white; color: blue;">&gt;
  &lt;</span><span style="background: white; color: rgb(163, 21, 21);">system.web</span><span style="background: white; color: blue;">&gt;
    &lt;</span><span style="background: yellow; color: rgb(163, 21, 21);">compilation </span><span style="background: yellow; color: red;">debug</span><span style="background: yellow; color: blue;">=</span><span style="background: yellow; color: black;">&quot;</span><span style="background: yellow; color: blue;">false</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: red;">targetFramework</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">4.0</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: blue;">/&gt;
  &lt;/</span><span style="background: white; color: rgb(163, 21, 21);">system.web</span><span style="background: white; color: blue;">&gt;
  &lt;!--</span><span style="background: white; color: green;">Elements removed for clarity.</span><span style="background: white; color: blue;">--&gt;
</span><span style="background: white; color: blue;">&lt;/</span><span style="background: white; color: rgb(163, 21, 21);">configuration</span><span style="background: white; color: blue;">&gt;</span></pre>]]></content:encoded>
    </item>
    <item>
      <title>InitializeSimpleMembership Attribute and SimpleMembership Exceptions</title>
      <link>https://docs.microsoft.com/archive/blogs/rickandy/initializesimplemembership-attribute-and-simplemembership-exceptions</link>
      <pubDate>Wed, 15 Aug 2012 09:44:00 GMT</pubDate>
      <dc:creator><![CDATA[Rick_Anderson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rickandy/2012/08/15/initializesimplemembership-attribute-and-simplemembership-exceptions/</guid>
      <description><![CDATA[The InitializeSimpleMembership Attribute ensures that before any membership (login/register) related...]]></description>
      <content:encoded><![CDATA[<p>The InitializeSimpleMembership Attribute ensures that before any membership (login/register) related functionality is run, that the membership database has been created. If the database is not yet created, the code will automatically create one. If the simple membership initialization fails, the Web Application can continue to run requests that don’t require membership.</p>  <p>Simple membership initialization failure can occur for the following reasons. </p>  <ol>   <li>The most common reason is the connection string to SQL Server is not valid. For example, you might not have SQL Server available. This is a frequent cause of failure in Azure. The ASP.NET MVC 4 templates by default use SqlExpress when created with Visual Studio 2010 and LocalDB when using Visual Studio 2012. SqlExpress is not installed on Azure and LocalDB does not run on Azure.</li>    <li>Multiple <a href="https://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext(v=VS.103).aspx" target="_blank">DBContext</a> objects on the same database.</li> </ol>  <p>The following code shows the InitializeSimpleMembership Attribute code that is added to a new ASP.NET MVC application. The code is found in the Filters folder:</p>  <pre class="code"><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">System;
</span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">System.Data.Entity;
</span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">System.Data.Entity.Infrastructure;
</span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">System.Threading;
</span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">System.Web.Mvc;
</span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">WebMatrix.WebData;
</span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">MvcV4.Models;

</span><span style="background: white; color: blue;">namespace </span><span style="background: white; color: black;">MvcV4.Filters
{
    [</span><span style="background: white; color: rgb(43, 145, 175);">AttributeUsage</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(43, 145, 175);">AttributeTargets</span><span style="background: white; color: black;">.Class | </span><span style="background: white; color: rgb(43, 145, 175);">AttributeTargets</span><span style="background: white; color: black;">.Method, AllowMultiple = </span><span style="background: white; color: blue;">false</span><span style="background: white; color: black;">, Inherited = </span><span style="background: white; color: blue;">true</span><span style="background: white; color: black;">)]
    </span><span style="background: white; color: blue;">public sealed class </span><span style="background: white; color: rgb(43, 145, 175);">InitializeSimpleMembershipAttribute </span><span style="background: white; color: black;">: </span><span style="background: white; color: rgb(43, 145, 175);">ActionFilterAttribute
    </span><span style="background: white; color: black;">{
        </span><span style="background: white; color: blue;">private static </span><span style="background: white; color: rgb(43, 145, 175);">SimpleMembershipInitializer </span><span style="background: white; color: black;">_initializer;
        </span><span style="background: white; color: blue;">private static object </span><span style="background: white; color: black;">_initializerLock = </span><span style="background: white; color: blue;">new object</span><span style="background: white; color: black;">();
        </span><span style="background: white; color: blue;">private static bool </span><span style="background: white; color: black;">_isInitialized;

        </span><span style="background: white; color: blue;">public override void </span><span style="background: white; color: black;">OnActionExecuting(</span><span style="background: white; color: rgb(43, 145, 175);">ActionExecutingContext </span><span style="background: white; color: black;">filterContext)
        {
            </span><span style="background: white; color: green;">// Ensure ASP.NET Simple Membership is initialized only once per app start
            </span><span style="background: white; color: rgb(43, 145, 175);">LazyInitializer</span><span style="background: white; color: black;">.EnsureInitialized(</span><span style="background: white; color: blue;">ref </span><span style="background: white; color: black;">_initializer, </span><span style="background: white; color: blue;">ref </span><span style="background: white; color: black;">_isInitialized, </span><span style="background: white; color: blue;">ref </span><span style="background: white; color: black;">_initializerLock);
        }

        </span><span style="background: white; color: blue;">private class </span><span style="background: white; color: rgb(43, 145, 175);">SimpleMembershipInitializer
        </span><span style="background: white; color: black;">{
            </span><span style="background: white; color: blue;">public </span><span style="background: white; color: black;">SimpleMembershipInitializer()
            {
                </span><span style="background: white; color: rgb(43, 145, 175);">Database</span><span style="background: white; color: black;">.SetInitializer&lt;</span><span style="background: white; color: rgb(43, 145, 175);">UsersContext</span><span style="background: white; color: black;">&gt;(</span><span style="background: white; color: blue;">null</span><span style="background: white; color: black;">);

                </span><span style="background: white; color: blue;">try
                </span><span style="background: white; color: black;">{
                    </span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">(</span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">context = </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">UsersContext</span><span style="background: white; color: black;">())
                    {
                        </span><span style="background: white; color: blue;">if </span><span style="background: white; color: black;">(!context.Database.Exists())
                        {
                            </span><span style="background: white; color: green;">// Create the SimpleMembership database without Entity Framework migration schema
                            </span><span style="background: white; color: black;">((</span><span style="background: white; color: rgb(43, 145, 175);">IObjectContextAdapter</span><span style="background: white; color: black;">)context).ObjectContext.CreateDatabase();
                        }
                    }

                    </span><span style="background: white; color: rgb(43, 145, 175);">WebSecurity</span><span style="background: white; color: black;">.InitializeDatabaseConnection(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;DefaultConnection&quot;</span><span style="background: white; color: black;">, </span><span style="background: white; color: rgb(163, 21, 21);">&quot;UserProfile&quot;</span><span style="background: white; color: black;">, </span><span style="background: white; color: rgb(163, 21, 21);">&quot;UserId&quot;</span><span style="background: white; color: black;">, </span><span style="background: white; color: rgb(163, 21, 21);">&quot;UserName&quot;</span><span style="background: white; color: black;">, autoCreateTables: </span><span style="background: white; color: blue;">true</span><span style="background: white; color: black;">);
                }
                </span><span style="background: white; color: blue;">catch </span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(43, 145, 175);">Exception </span><span style="background: white; color: black;">ex)
                {
                    </span><span style="background: white; color: blue;">throw new </span><span style="background: white; color: rgb(43, 145, 175);">InvalidOperationException</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;The ASP.NET Simple Membership database could not be initialized. For more information, please see https://go.microsoft.com/fwlink/?LinkId=256588&quot;</span><span style="background: white; color: black;">, ex);
                }
            }
        }
    }
}
</span></pre>]]></content:encoded>
    </item>
    <item>
      <title>Adding Bundling and Minification to Web Forms</title>
      <link>https://docs.microsoft.com/archive/blogs/rickandy/adding-bundling-and-minification-to-web-forms</link>
      <pubDate>Tue, 14 Aug 2012 15:21:00 GMT</pubDate>
      <dc:creator><![CDATA[Rick_Anderson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rickandy/2012/08/14/adding-bundling-and-minification-to-web-forms/</guid>
      <description><![CDATA[My&#160;&#160; B/M tutorial provides a good introduction to benefits of Bundling and Minification....]]></description>
      <content:encoded><![CDATA[<p>My&#160;&#160; <a href="https://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification" target="_blank">B/M tutorial</a> provides a good introduction to benefits of Bundling and Minification. You should read it to become familiar with the bundling and minification. This blog will focus on using B/M with Web Forms, my B/M tutorial focused on ASP.NET MVC.</p>  <p>Create a new ASP.NET Web Forms application which targets the .Net 4.5 framework.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/4643.NewProj_654A4302.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/4643.NewProj_5F00_654A4302.png"><img title="NewProj" style="display: inline; background-image: none;" border="0" alt="NewProj" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/3157.NewProj_thumb_1022A715.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/3157.NewProj_5F00_thumb_5F00_1022A715.png" width="538" height="229" /></a></p>  <p> Run the application launch the IE F-12 developer tools. Select the Script tab, then use the assets button to view the JavaScript files.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/1106.F12_Script_65B32A6F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/1106.F12_5F00_Script_5F00_65B32A6F.png"><img title="F12_Script" style="display: inline; background-image: none;" border="0" alt="F12_Script" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/11/73/metablogapi/5381.F12_Script_thumb_108B8E82.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-11-73-metablogapi/5381.F12_5F00_Script_5F00_thumb_5F00_108B8E82.png" width="528" height="483" /></a></p>  <p>You can select one of the JavaScript files and view it in the left pane. Note the full (non-minimized version) of the files are used.</p>  <h3><font face="Lucida Console"></font></h3>  <h3>Creating the jQuery Bundles</h3>  <p>Add jQuery, jQuery.UI and jQuery validation to the&#160; <strong>BundleConfig</strong> class in the <strong>App_Start</strong> folder. The following code shows the complete class:</p>  <pre class="code"><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">System.Web.Optimization;

</span><span style="background: white; color: blue;">public class </span><span style="background: white; color: rgb(43, 145, 175);">BundleConfig
</span><span style="background: white; color: black;">{
    </span><span style="background: white; color: blue;">public static void </span><span style="background: white; color: black;">RegisterBundles(</span><span style="background: white; color: rgb(43, 145, 175);">BundleCollection </span><span style="background: white; color: black;">bundles)
    {
        bundles.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">ScriptBundle</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/jquery&quot;</span><span style="background: white; color: black;">).Include(
                    </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/jquery-{version}.js&quot;</span><span style="background: white; color: black;">));

        bundles.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">ScriptBundle</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/jqueryui&quot;</span><span style="background: white; color: black;">).Include(
                    </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/jquery-ui-{version}.js&quot;</span><span style="background: white; color: black;">));

        bundles.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">ScriptBundle</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/jqueryval&quot;</span><span style="background: white; color: black;">).Include(
                    </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/jquery.unobtrusive*&quot;</span><span style="background: white; color: black;">,
                    </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/jquery.validate*&quot;</span><span style="background: white; color: black;">));

        bundles.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">ScriptBundle</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/WebFormsJs&quot;</span><span style="background: white; color: black;">).Include(
              </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/WebForms/WebForms.js&quot;</span><span style="background: white; color: black;">,
              </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/WebForms/WebUIValidation.js&quot;</span><span style="background: white; color: black;">,
              </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/WebForms/MenuStandards.js&quot;</span><span style="background: white; color: black;">,
              </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/WebForms/Focus.js&quot;</span><span style="background: white; color: black;">,
              </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/WebForms/GridView.js&quot;</span><span style="background: white; color: black;">,
              </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/WebForms/DetailsView.js&quot;</span><span style="background: white; color: black;">,
              </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/WebForms/TreeView.js&quot;</span><span style="background: white; color: black;">,
              </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/WebForms/WebParts.js&quot;</span><span style="background: white; color: black;">));

        bundles.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">ScriptBundle</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/MsAjaxJs&quot;</span><span style="background: white; color: black;">).Include(
            </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/WebForms/MsAjax/MicrosoftAjax.js&quot;</span><span style="background: white; color: black;">,
            </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/WebForms/MsAjax/MicrosoftAjaxApplicationServices.js&quot;</span><span style="background: white; color: black;">,
            </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/WebForms/MsAjax/MicrosoftAjaxTimer.js&quot;</span><span style="background: white; color: black;">,
            </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/WebForms/MsAjax/MicrosoftAjaxWebForms.js&quot;</span><span style="background: white; color: black;">));

        bundles.Add(</span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">ScriptBundle</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/modernizr&quot;</span><span style="background: white; color: black;">).Include(
            </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Scripts/modernizr-*&quot;</span><span style="background: white; color: black;">));
    }
}
</span></pre>

<h3>Register the Bundles</h3>

<p>The templates create the code hook up the bundle registration in the <strong>Application_Start</strong> method in the <em>Global.asax</em> file.</p>

<pre class="code"><span style="background: white; color: blue;">void </span><span style="background: white; color: black;">Application_Start(</span><span style="background: white; color: blue;">object </span><span style="background: white; color: black;">sender, </span><span style="background: white; color: rgb(43, 145, 175);">EventArgs </span><span style="background: white; color: black;">e)
{
    </span><span style="background: yellow; color: rgb(43, 145, 175);">BundleConfig</span><span style="background: yellow; color: black;">.RegisterBundles(</span><span style="background: yellow; color: rgb(43, 145, 175);">BundleTable</span><span style="background: yellow; color: black;">.Bundles);
    </span><span style="background: white; color: rgb(43, 145, 175);">AuthConfig</span><span style="background: white; color: black;">.RegisterOpenAuth();
}</span></pre>

<h3>Reference the Bundles</h3>

<p><span style="background: white; color: blue;"></span></p>

<pre class="code">Add the jQuery bundles to the <span style="background: white; color: blue;">&lt;</span><span style="background: white; color: maroon;">asp</span><span style="background: white; color: blue;">:</span><span style="background: white; color: maroon;">PlaceHolder &gt; </span>markup as shown in the following code:</pre>

<pre class="code"><span style="background: white; color: black;">    </span><span style="background: white; color: blue;">&lt;</span><span style="background: white; color: maroon;">asp</span><span style="background: white; color: blue;">:</span><span style="background: white; color: maroon;">PlaceHolder </span><span style="background: white; color: red;">runat</span><span style="background: white; color: blue;">=&quot;server&quot;&gt;        
         </span><span style="background: yellow; color: black;">&lt;%</span><span style="background: white; color: blue;">: </span><span style="background: white; color: black;">Scripts.Render(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/modernizr&quot;</span><span style="background: white; color: black;">) </span><span style="background: yellow; color: black;">%&gt;
</span><span style="background: white; color: black;">         </span><span style="background: yellow; color: black;">&lt;%</span><span style="background: white; color: blue;">: </span><span style="background: white; color: black;">Scripts.Render(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/jquery&quot;</span><span style="background: white; color: black;">) </span><span style="background: yellow; color: black;">%&gt;
</span><span style="background: white; color: black;">         </span><span style="background: yellow; color: black;">&lt;%</span><span style="background: white; color: blue;">: </span><span style="background: white; color: black;">Scripts.Render(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/jqueryui&quot;</span><span style="background: white; color: black;">) </span><span style="background: yellow; color: black;">%&gt;
</span><span style="background: white; color: black;">    </span><span style="background: white; color: blue;">&lt;/</span><span style="background: white; color: maroon;">asp</span><span style="background: white; color: blue;">:</span><span style="background: white; color: maroon;">PlaceHolder</span><span style="background: white; color: blue;">&gt;</span></pre>

<pre class="code">Comment out the jQuery script references in the ScriptManager tag as shown below:</pre>

<pre class="code"><span style="background: white; color: blue;">&lt;</span><span style="background: white; color: maroon;">body</span><span style="background: white; color: blue;">&gt;
    &lt;</span><span style="background: white; color: maroon;">form </span><span style="background: white; color: red;">runat</span><span style="background: white; color: blue;">=&quot;server&quot;&gt;
    &lt;</span><span style="background: white; color: maroon;">asp</span><span style="background: white; color: blue;">:</span><span style="background: white; color: maroon;">ScriptManager </span><span style="background: white; color: red;">runat</span><span style="background: white; color: blue;">=&quot;server&quot;&gt;
        &lt;</span><span style="background: white; color: maroon;">Scripts</span><span style="background: white; color: blue;">&gt;
            </span><span style="background: yellow; color: black;">&lt;%</span><span style="background: white; color: rgb(0, 100, 0);">--        
            &lt;asp:ScriptReference Name=&quot;jquery&quot; /&gt;
            &lt;asp:ScriptReference Name=&quot;jquery.ui.combined&quot; /&gt;
            --</span><span style="background: yellow; color: black;">%&gt;
</span><span style="background: white; color: black;">        </span><span style="background: white; color: blue;">&lt;/</span><span style="background: white; color: maroon;">Scripts</span><span style="background: white; color: blue;">&gt;
    &lt;/</span><span style="background: white; color: maroon;">asp</span><span style="background: white; color: blue;">:</span><span style="background: white; color: maroon;">ScriptManager</span><span style="background: white; color: blue;">&gt;
    &lt;</span><span style="background: white; color: maroon;">header</span><span style="background: white; color: blue;">&gt;</span></pre>

<p><span style="background: white; color: blue;"></span></p>

<p><span style="background: white; color: blue;"></span></p>

<p><span style="background: white; color: blue;"></span></p>

<h3>CSS Bundles</h3>

<p>Examine the <em>Bundle.config</em> file, which contains the markup to create CSS style bundles.</p>

<pre class="code"><span style="background: white; color: blue;">&lt;?</span><span style="background: white; color: rgb(163, 21, 21);">xml </span><span style="background: white; color: red;">version</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">1.0</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: red;">encoding</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">utf-8</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: blue;">?&gt;
&lt;</span><span style="background: white; color: rgb(163, 21, 21);">bundles </span><span style="background: white; color: red;">version</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">1.0</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">&gt;
  &lt;</span><span style="background: white; color: rgb(163, 21, 21);">styleBundle </span><span style="background: white; color: red;">path</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">~/Content/css</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">&gt;
    &lt;</span><span style="background: white; color: rgb(163, 21, 21);">include </span><span style="background: white; color: red;">path</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">~/Content/Site.css</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: blue;">/&gt;
  &lt;/</span><span style="background: white; color: rgb(163, 21, 21);">styleBundle</span><span style="background: white; color: blue;">&gt;
  &lt;</span><span style="background: white; color: rgb(163, 21, 21);">styleBundle </span><span style="background: white; color: red;">path</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">~/Content/themes/base/css</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">&gt;
    &lt;</span><span style="background: white; color: rgb(163, 21, 21);">include </span><span style="background: white; color: red;">path</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">~/Content/themes/base/jquery.ui.core.css</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: blue;">/&gt;
    &lt;</span><span style="background: white; color: rgb(163, 21, 21);">include </span><span style="background: white; color: red;">path</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">~/Content/themes/base/jquery.ui.resizable.css</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: blue;">/&gt;
    &lt;</span><span style="background: white; color: rgb(163, 21, 21);">include </span><span style="background: white; color: red;">path</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">~/Content/themes/base/jquery.ui.selectable.css</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: blue;">/&gt;
    &lt;</span><span style="background: white; color: rgb(163, 21, 21);">include </span><span style="background: white; color: red;">path</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">~/Content/themes/base/jquery.ui.accordion.css</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: blue;">/&gt;
    &lt;</span><span style="background: white; color: rgb(163, 21, 21);">include </span><span style="background: white; color: red;">path</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">~/Content/themes/base/jquery.ui.autocomplete.css</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: blue;">/&gt;
    &lt;</span><span style="background: white; color: rgb(163, 21, 21);">include </span><span style="background: white; color: red;">path</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">~/Content/themes/base/jquery.ui.button.css</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: blue;">/&gt;
    &lt;</span><span style="background: white; color: rgb(163, 21, 21);">include </span><span style="background: white; color: red;">path</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">~/Content/themes/base/jquery.ui.dialog.css</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: blue;">/&gt;
    &lt;</span><span style="background: white; color: rgb(163, 21, 21);">include </span><span style="background: white; color: red;">path</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">~/Content/themes/base/jquery.ui.slider.css</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: blue;">/&gt;
    &lt;</span><span style="background: white; color: rgb(163, 21, 21);">include </span><span style="background: white; color: red;">path</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">~/Content/themes/base/jquery.ui.tabs.css</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: blue;">/&gt;
    &lt;</span><span style="background: white; color: rgb(163, 21, 21);">include </span><span style="background: white; color: red;">path</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">~/Content/themes/base/jquery.ui.datepicker.css</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: blue;">/&gt;
    &lt;</span><span style="background: white; color: rgb(163, 21, 21);">include </span><span style="background: white; color: red;">path</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">~/Content/themes/base/jquery.ui.progressbar.css</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: blue;">/&gt;
    &lt;</span><span style="background: white; color: rgb(163, 21, 21);">include </span><span style="background: white; color: red;">path</span><span style="background: white; color: blue;">=</span><span style="background: white; color: black;">&quot;</span><span style="background: white; color: blue;">~/Content/themes/base/jquery.ui.theme.css</span><span style="background: white; color: black;">&quot; </span><span style="background: white; color: blue;">/&gt;
  &lt;/</span><span style="background: white; color: rgb(163, 21, 21);">styleBundle</span><span style="background: white; color: blue;">&gt;
&lt;/</span><span style="background: white; color: rgb(163, 21, 21);">bundles</span><span style="background: white; color: blue;">&gt;
</span></pre>

<p>&#160;</p>

<p>You can add your own style bundles to the <em>Bundle.config</em> file.</p>

<p>The following markup shows the CSS bundles and JavaScript bundles referenced. Note that you can multiple bundles in one call to the Render method.</p>

<pre class="code"><span style="background: yellow; color: black;">&lt;%</span><span style="background: white; color: blue;">: </span><span style="background: white; color: rgb(43, 145, 175);">Styles</span><span style="background: white; color: black;">.Render(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/themes/base/css&quot;</span><span style="background: white; color: black;">, 
                    </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/Content/css&quot;</span><span style="background: white; color: black;">) </span><span style="background: yellow; color: black;">%&gt;
&lt;%</span><span style="background: white; color: blue;">: </span><span style="background: white; color: rgb(43, 145, 175);">Scripts</span><span style="background: white; color: black;">.Render(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/modernizr&quot;</span><span style="background: white; color: black;">) </span><span style="background: yellow; color: black;">%&gt;
&lt;%</span><span style="background: white; color: blue;">: </span><span style="background: white; color: rgb(43, 145, 175);">Scripts</span><span style="background: white; color: black;">.Render(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/jquery&quot;</span><span style="background: white; color: black;">,
                    </span><span style="background: white; color: rgb(163, 21, 21);">&quot;~/bundles/jqueryui&quot;</span><span style="background: white; color: black;">) </span><span style="background: yellow; color: black;">%&gt;</span></pre>]]></content:encoded>
    </item>
  </channel>
</rss>