<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://cicoria.com/cs1/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Shawn Cicoria - CedarLogic</title><link>http://cicoria.com/cs1/blogs/cedarlogic/default.aspx</link><description>Perspectives and Observations on Technology</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Turning off the Visual Studio “Attach to process” security warning…</title><link>http://cicoria.com/cs1/blogs/cedarlogic/archive/2012/04/12/turning-off-the-visual-studio-attach-to-process-security-warning.aspx</link><pubDate>Thu, 12 Apr 2012 12:58:46 GMT</pubDate><guid isPermaLink="false">29a00c46-c030-43c5-bbda-4d08b2dd4d56:2935</guid><dc:creator>cicorias</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://cicoria.com/cs1/blogs/cedarlogic/rsscomments.aspx?PostID=2935</wfw:commentRss><comments>http://cicoria.com/cs1/blogs/cedarlogic/archive/2012/04/12/turning-off-the-visual-studio-attach-to-process-security-warning.aspx#comments</comments><description>&lt;p&gt;When you’re urnning under x64 you have to affect 1 addition spot in the registry to disable this warning – which clearly should only be done by folks that know what they’re doing.&lt;/p&gt;  &lt;p&gt;NOTE: affecting the registry can be harmful – do so at your own risk.&lt;/p&gt;  &lt;p&gt;Windows Registry Editor Version 5.00&lt;/p&gt;  &lt;pre class="brush: plain;"&gt;Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Debugger]
&amp;quot;DisableAttachSecurityWarning&amp;quot;=dword:00000001

[HKEY_CURRENT_USER\Software\Wow6432Node\Microsoft\VisualStudio\10.0\Debugger]
&amp;quot;DisableAttachSecurityWarning&amp;quot;=dword:00000001&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://cicoria.com/cs1/aggbug.aspx?PostID=2935" width="1" height="1"&gt;</description><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Development/default.aspx">Development</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Troubleshooting/default.aspx">Troubleshooting</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Debugging/default.aspx">Debugging</category></item><item><title>Getting a SecurityToken from a RequestSecurityTokenResponse in WIF</title><link>http://cicoria.com/cs1/blogs/cedarlogic/archive/2012/03/22/getting-a-securitytoken-from-a-requestsecuritytokenresponse-in-wif.aspx</link><pubDate>Thu, 22 Mar 2012 21:22:10 GMT</pubDate><guid isPermaLink="false">29a00c46-c030-43c5-bbda-4d08b2dd4d56:2934</guid><dc:creator>cicorias</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://cicoria.com/cs1/blogs/cedarlogic/rsscomments.aspx?PostID=2934</wfw:commentRss><comments>http://cicoria.com/cs1/blogs/cedarlogic/archive/2012/03/22/getting-a-securitytoken-from-a-requestsecuritytokenresponse-in-wif.aspx#comments</comments><description>&lt;p&gt;When you’re working with WIF and WSTrustChannelFactory when you call the Issue operation, you can also request that a RequestSecurityTokenResponse as an out parameter.&lt;/p&gt;  &lt;p&gt;However, what can you do with that object?&amp;#160; Well, you could keep it around and use it for subsequent calls with the extension method CreateChannelWithIssuedToken – or can you?&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;public static T CreateChannelWithIssuedToken&amp;lt;T&amp;gt;(this ChannelFactory&amp;lt;T&amp;gt; factory, SecurityToken issuedToken);&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;As you can see from the method signature it takes a SecurityToken – but that’s not present on the RequestSecurityTokenResponse class.&lt;/p&gt;

&lt;p&gt;However, you can through a little magic get a GenericXmlSecurityToken by means of the following set of extension methods below – just call &lt;/p&gt;

&lt;p&gt;rstr.GetSecurityTokenFromResponse() – and you’ll get a GenericXmlSecurityToken as a return.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public static class TokenHelper
{


    /// &amp;lt;summary&amp;gt;
    /// Takes a RequestSecurityTokenResponse, pulls out the GenericXmlSecurityToken usable for further WS-Trust calls
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;rstr&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
    public static GenericXmlSecurityToken GetSecurityTokenFromResponse(this RequestSecurityTokenResponse rstr)
    {
        var lifeTime = rstr.Lifetime;
        var appliesTo = rstr.AppliesTo.Uri;
        var tokenXml = rstr.GetSerializedTokenFromResponse();
        var token = GetTokenFromSerializedToken(tokenXml, appliesTo, lifeTime);
        return token;
    }

    /// &amp;lt;summary&amp;gt;
    /// Provides a token as an XML string.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;rstr&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
    public static string GetSerializedTokenFromResponse(this RequestSecurityTokenResponse rstr)
    {
        var serializedRst = new WSFederationSerializer().GetResponseAsString(rstr, new WSTrustSerializationContext());
        return serializedRst;
    }

    /// &amp;lt;summary&amp;gt;
    /// Turns the XML representation of the token back into a GenericXmlSecurityToken.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;tokenAsXmlString&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;param name=&amp;quot;appliesTo&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;param name=&amp;quot;lifetime&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
    public static GenericXmlSecurityToken GetTokenFromSerializedToken(this string tokenAsXmlString, Uri appliesTo, Lifetime lifetime)
    {
        RequestSecurityTokenResponse rstr2 = new WSFederationSerializer().CreateResponse(
        new SignInResponseMessage(appliesTo, tokenAsXmlString),
        new WSTrustSerializationContext());
        return new GenericXmlSecurityToken(
            rstr2.RequestedSecurityToken.SecurityTokenXml,
            new BinarySecretSecurityToken(
                rstr2.RequestedProofToken.ProtectedKey.GetKeyBytes()),
            lifetime.Created.HasValue ? lifetime.Created.Value : DateTime.MinValue,
            lifetime.Expires.HasValue ? lifetime.Expires.Value : DateTime.MaxValue,
            rstr2.RequestedAttachedReference,
            rstr2.RequestedUnattachedReference,
            null);
    }

}&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://cicoria.com/cs1/aggbug.aspx?PostID=2934" width="1" height="1"&gt;</description><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/.NET/default.aspx">.NET</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/WCF+_2800_Indigo_2900_/default.aspx">WCF (Indigo)</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Federation/default.aspx">Federation</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Security/default.aspx">Security</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/ADFS/default.aspx">ADFS</category></item><item><title>Learn More about Microsoft Codename "Trust Services" - TechNet Articles - Home - TechNet Wiki</title><link>http://cicoria.com/cs1/blogs/cedarlogic/archive/2012/02/04/learn-more-about-microsoft-codename-quot-trust-services-quot-technet-articles-home-technet-wiki.aspx</link><pubDate>Sat, 04 Feb 2012 14:50:45 GMT</pubDate><guid isPermaLink="false">29a00c46-c030-43c5-bbda-4d08b2dd4d56:2932</guid><dc:creator>cicorias</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://cicoria.com/cs1/blogs/cedarlogic/rsscomments.aspx?PostID=2932</wfw:commentRss><comments>http://cicoria.com/cs1/blogs/cedarlogic/archive/2012/02/04/learn-more-about-microsoft-codename-quot-trust-services-quot-technet-articles-home-technet-wiki.aspx#comments</comments><description>&lt;p&gt;Many companies, ISV’s, and solutions have concerns about data in the cloud.&amp;#160; With PKI based encryption, Trust Services provides key management for your publisher/subscribers and a simplified SDK set of classes to abstract the encryption, decryption process.&amp;#160; Both managed classes and PowerShell add-in provided...&lt;/p&gt;  &lt;p&gt;&lt;a href="http://social.technet.microsoft.com/wiki/contents/articles/7041.learn-more-about-microsoft-codename-trust-services.aspx"&gt;Learn More about Microsoft Codename &amp;quot;Trust Services&amp;quot; - TechNet Articles - Home - TechNet Wiki&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://cicoria.com/cs1/aggbug.aspx?PostID=2932" width="1" height="1"&gt;</description><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Azure/default.aspx">Azure</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Security/default.aspx">Security</category></item><item><title>Making Windows Azure Drive Letter Persistent</title><link>http://cicoria.com/cs1/blogs/cedarlogic/archive/2012/01/19/making-windows-azure-drive-letter-persistent.aspx</link><pubDate>Thu, 19 Jan 2012 20:39:49 GMT</pubDate><guid isPermaLink="false">29a00c46-c030-43c5-bbda-4d08b2dd4d56:2931</guid><dc:creator>cicorias</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://cicoria.com/cs1/blogs/cedarlogic/rsscomments.aspx?PostID=2931</wfw:commentRss><comments>http://cicoria.com/cs1/blogs/cedarlogic/archive/2012/01/19/making-windows-azure-drive-letter-persistent.aspx#comments</comments><description>&lt;p&gt;Windows Azure Fieldnote&lt;/p&gt;  &lt;h3&gt;Summary&lt;/h3&gt;  &lt;p&gt;Windows Azure Drives [1] provide a means to represent a file based (disk drive) persistent storage option for the various role types within Windows Azure Compute. Each of the roles within Windows Azure can mount and utilize for persistent storage (that survives reboot, reimaging, and updated deployments, of a role instances). &lt;/p&gt;  &lt;p&gt;During the mounting of a VHD as a &lt;b&gt;CloudDrive&lt;/b&gt;, the managed classes have no means to control the drive letter assignment this directly through the &lt;b&gt;CloudDrive&lt;/b&gt; managed classes that are provided through the Windows Azure SDK.&lt;/p&gt;  &lt;h3&gt;Problem&lt;/h3&gt;  &lt;p&gt;Many solutions today require the use of standard Windows File IO based access and instead of refactoring solutions to leverage the storage options available in the PaaS part of the Windows Azure platform, solutions deployed to Windows Azure can mount a Virtual Hard Disk (VHD) that is persisted in a storage account inside of a running instance. That Page Blob backed VHD is then represented through Virtual Disk Services and Windows Cloud Drive services to the running instances as a Disk Drive and addressable through File IO using a Drive Letter.&lt;/p&gt;  &lt;p&gt;While a persistent drive option is available, the drive letter assignment is determined at runtime during the mounting process. This potentially presents a problem with existing solutions, codebases, libraries that require a setting to be established prior to runtime. For example, an application configuration setting that provides a full path, including the drive letter to a location for read/write access for File IO.&lt;/p&gt;  &lt;h3&gt;Solution&lt;/h3&gt;  &lt;p&gt;The following solution takes advantage of the Virtual Disk Services through the &lt;b&gt;DiskPart.exe&lt;/b&gt; operating system utility to first identify what the VHD is mounted as and, select that volume, and re-assign the letter to the target drive letter.&lt;/p&gt;  &lt;p&gt;The original idea for the approach comes from this blog post here: &lt;a href="http://techyfreak.blogspot.com/2011/02/changing-drive-letter-of-azure-drive.html"&gt;http://techyfreak.blogspot.com/2011/02/changing-drive-letter-of-azure-drive.html&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;While there is a COM interface available that could be wrapped via an interop layer, the choice was made to initiate a process to take the actions required for remapping the drive letter due to simplicity. Additionally, while there is an existing managed Interop assembly available (&lt;strong&gt;Microsoft.Storage.Vds&lt;/strong&gt;) that is an undocumented and unsupported assembly.&lt;/p&gt;  &lt;p&gt;The example scenario presented does the following:&lt;/p&gt;  &lt;p&gt;1. Leverages a Windows Azure Web Role (could be a Worker Role or VM Role as well)&lt;/p&gt;  &lt;p&gt;2. Implements a Windows Console applications that:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;a. Is a Startup task – in elevated mode and background&lt;/p&gt;    &lt;p&gt;b. Runs elevated in order to affect Virtual Disk Services&lt;/p&gt;    &lt;p&gt;c. At startup:&lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;Mounts the VHD from Windows Azure Storage&lt;/li&gt;      &lt;li&gt;Detects if target drive letter and re-assigns as needed to target drive letter **&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;d. Then Continuously (every 30 seconds)&lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;i. Checks if drive is mounted on target drive letter&lt;/li&gt;      &lt;li&gt;ii. If not, reassigns drive letter **&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;** Drive Letter reassignment is done through a &lt;i&gt;System.Process&lt;/i&gt; startup object that runs Diskpart.exe with a “select volume” and “assign drive letter” command sequence.&lt;/b&gt;&lt;/p&gt;  &lt;h3&gt;Implementation&lt;/h3&gt;  &lt;p&gt;The sample solution contains the following:&lt;/p&gt;  &lt;p&gt;1. Windows Azure Web Role – simple MVC3 application that just lists the mapped &lt;b&gt;CloudDrives&lt;/b&gt; using the &lt;b&gt;CloudDrive.GetMountedDrives()&lt;/b&gt; method&lt;/p&gt;  &lt;p&gt;2. &lt;b&gt;CloudDriveManager&lt;/b&gt; class library – helper class that provides the CloudDrive management actions leveraged by the caller (either Console or other code)&lt;/p&gt;  &lt;p&gt;3. &lt;b&gt;CloudDriveManagerConsole&lt;/b&gt; – Windows console application intended to be a startup project and running in elevated mode in order to affect the assigned driver letter&lt;/p&gt;  &lt;p&gt;4. &lt;b&gt;CloudDriveManagerRole&lt;/b&gt; – implementation of &lt;b&gt;Microsoft.WindowsAzure.ServiceRuntime.RoleEntryPoint&lt;/b&gt; – which allows this class to be used from within a Windows Azure Web or Worker role – however, that role entry point would need to be elevated (via the “&lt;b&gt;Runtime&lt;/b&gt;” and “&lt;b&gt;NetFxEntryPoint&lt;/b&gt;” Elements)&lt;/p&gt;  &lt;p&gt;5. &lt;b&gt;Logger&lt;/b&gt; – simple logger class that writes to a Queue for debugging purposes&lt;/p&gt;  &lt;p&gt;6. &lt;b&gt;ResponseViewer&lt;/b&gt; – simple WPF application that reads Queue messages so you can view log messages from your cloud instances – purely for debugging purposes&lt;/p&gt;  &lt;p&gt;7. &lt;b&gt;TestListDrives&lt;/b&gt; – simple Windows console application that lists the mapped &lt;b&gt;CloudDrives&lt;/b&gt; – usable from within the Role instance by using Remote Desktop and connecting to the instance&lt;/p&gt;  &lt;h4&gt;Instance Initialization&lt;/h4&gt;  &lt;p&gt;During role startup, Windows Azure will execute the Task defined in the Service definition in background mode and elevated (running as system). Inside of the console application, the implementation of &lt;b&gt;OnStart&lt;/b&gt; does the following:&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;public override bool OnStart()
{
    try
    {
        Initialize();
        MountAllDrives();
    }
    catch (Exception ex)
    {
        _logger.Log(&amp;quot;fail on onstart&amp;quot;, ex);
    }
    return true;
}

void MountAllDrives()
{
    try
    {
        var driveSettings = RoleEnvironment.GetConfigurationSettingValue(DRIVE_SETTINGS);
        string[] settings = driveSettings.Split(&amp;#39;:&amp;#39;);
        CloudStorageAccount account =CoudStorageAccount.FromConfigurationSetting(STORAGE_ACCOUNT_SETTING);
        string dCacheName = RoleEnvironment.GetConfigurationSettingValue(DCACHE_NAME);
        LocalResource cache = RoleEnvironment.GetLocalResource(dCacheName);
        int cacheSize = cache.MaximumSizeInMegabytes / 2;
        _cloudDriveManager = new CloudDriveManager(account, settings[0], settings[1][0], cache);
        _cloudDriveManager.CreateDrive();
        _cloudDriveManager.Mount();
    }
    catch (Exception ex)
    {
        _logger.Log(&amp;quot;fail on mountalldrives&amp;quot;, ex);
        throw;
    }
}&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Mostly, the startup routine calls into the custom class &lt;b&gt;CloudDriveManager&lt;/b&gt;, which provides the simple abstraction to the Windows Azure &lt;b&gt;CloudDrive&lt;/b&gt; managed class.&lt;/p&gt;

&lt;p&gt;The custom &lt;b&gt;CreateDrive&lt;/b&gt; method calls the &lt;b&gt;CloudDrive&lt;/b&gt; create drive method in a non-destructive manner – and, for this sample, creates the initial VHD in storage if it does not already exist.&lt;/p&gt;

&lt;p&gt;Mounting calls the managed classes &lt;b&gt;CloudDrive.Moun&lt;/b&gt;t along with calling into a custom &lt;b&gt;VerifyDriveLetter&lt;/b&gt; method.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public void Mount()
{
    _logger.Log(string.Format(&amp;quot;mounting drive {0}&amp;quot;, _vhdName));
    _cloudDrive = _account.CreateCloudDrive(_vhdName);

    var driveLetter = _cloudDrive.Mount(_cacheSize, DriveMountOptions.Force);
    _logger.Log(string.Format(&amp;quot;mounted drive letter {0}&amp;quot;, driveLetter));

    var remounted = VerifyDriveLetter();
}&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Within &lt;b&gt;VerifyDriveLetter&lt;/b&gt; there’s some logic to validate the current state of the mounted drives. And then verification if the mounted drive is the intended drive letter.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public bool VerifyDriveLetter()
{
    _logger.Log(&amp;quot;verifying drive letter&amp;quot;);
    bool rv = false;
    if (RoleEnvironment.IsEmulated)
    {
        _logger.Log(&amp;quot;Can&amp;#39;t change drive letter in emulator&amp;quot;);
        //return;
    }

    try
    {
        DriveInfo d = new DriveInfo(_cloudDrive.LocalPath);
        if (string.IsNullOrEmpty(_cloudDrive.LocalPath))
        {
            _logger.Log(&amp;quot;verifydriveLetter: Not Mounted?&amp;quot;);
            throw new InvalidOperationException(&amp;quot;drive is notmounted&amp;quot;);
        }

        if (!char.IsLetter(_cloudDrive.LocalPath[0]))
        {
            _logger.Log(&amp;quot;verifiydriveLeter: Not a letter?&amp;quot;);
            throw new InvalidOperationException(&amp;quot;verifydriveletter - not a letter?&amp;quot;);
        }

        if (IsSameDrive())
        {
            _logger.Log(&amp;quot;is same drive; no need to diskpart...&amp;quot;);
            return true;
        }

        char mountedDriveLetter = CurrentLocalDrive(_vhdName);
        RunDiskPart(_driveLetter, mountedDriveLetter);

        if (!IsSameDrive())
        {
            var msg = &amp;quot;Drive change failed to change&amp;quot;;
                   _logger.Log(msg);
                   throw new ApplicationException(msg);
               }
               else
               {
                   Mount();
               }

               _logger.Log(&amp;quot;verifydriveletter done!!&amp;quot;);
               return rv;

           }
           catch (Exception ex)
           {
               _logger.Log(&amp;quot;error verifydriveletter&amp;quot;, ex);
               return rv;
           }

       }&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The &lt;b&gt;IsSameDrive&lt;/b&gt; method validates if the current mapped drive is indeed the planned drive letter. If not, it will return “false”.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;bool IsSameDrive()
{
    char targetDrive = _driveLetter.ToString().ToLower()[0];
    char currentDrive = CurrentLocalDrive(_vhdName);

    string msg = string.Format(
        &amp;quot;target drive: {0} - current drive: {1}&amp;quot;,
        targetDrive,
        currentDrive);

    _logger.Log(msg);

    if (targetDrive == currentDrive)
    {
        _logger.Log(&amp;quot;verifydriveLetter: already same drive&amp;quot;);
        return true;
    }
    else
        return false;

}&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Finally, the &lt;b&gt;RunDiskPart&lt;/b&gt; method initiates the action of spawning a new process with the dynamically created &lt;b&gt;DiskPart&lt;/b&gt; script file that selects the existing volume name (by drive letter) and assigns the target drive letter.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;void RunDiskPart(char destinationDriveLetter, char mountedDriveLetter)
{
    string diskpartFile = Path.Combine(_cache.RootPath, &amp;quot;diskpart.txt&amp;quot;);

    if (File.Exists(diskpartFile))
    {
        File.Delete(diskpartFile);
    }

    string cmd = &amp;quot;select volume = &amp;quot; + mountedDriveLetter + &amp;quot;\r\n&amp;quot; + &amp;quot;assign letter = &amp;quot; + destinationDriveLetter;
      File.WriteAllText(diskpartFile, cmd);

      //start the process
      _logger.Log(&amp;quot;running diskpart now!!!!&amp;quot;);
      _logger.Log(&amp;quot;using &amp;quot; + cmd);
      using (Process changeletter = new Process())
      {
          changeletter.StartInfo.Arguments = &amp;quot;/s&amp;quot; + &amp;quot; &amp;quot; + diskpartFile;
          changeletter.StartInfo.FileName = 
     System.Environment.GetEnvironmentVariable(&amp;quot;WINDIR&amp;quot;) + &amp;quot;\\System32\\diskpart.exe&amp;quot;;
        //#if !DEBUG
        changeletter.Start();
        changeletter.WaitForExit();
        //#endif
    }

    File.Delete(diskpartFile);

}&lt;/pre&gt;

&lt;h3&gt;Output and Results&lt;/h3&gt;

&lt;p&gt;As an example of the interaction and how the drive appears within the running Windows Azure Role, the following screen shots illustrate the results.&lt;/p&gt;

&lt;h4&gt;Program Startup&lt;/h4&gt;

&lt;p&gt;At program startup the drive is initially mounted by the Console application – immediately the drive is mounted as the F: drive – the startup code verifies if this is the intended drive – as shown below in the logs, it isn’t, so the code initiates the RunDiskPart method setting M: as the mapped drive.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/image_5F00_0A5030DA.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/image_5F00_thumb_5F00_33E3FC0D.png" width="574" height="408" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The following shows how a Windows Azure Drive appears after the custom code reassigns the drive letter to the Operating system using Windows Explorer – the drive is selected below.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/image_5F00_12845671.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/image_5F00_thumb_5F00_58951384.png" width="576" height="344" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Within the custom MVC3 application, which simply just lists the Mounted Windows Azure drive (which runs in a separate Process non-elevated – the drive appears as a regular Operating System drive – accessible for File IO as required using the intended drive letter.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/image_5F00_09B44E25.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/image_5F00_thumb_5F00_68C0DB7D.png" width="572" height="269" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;Forced Letter Change&lt;/h4&gt;

&lt;p&gt;The following shows what happens if the drive letter is intentionally changed – in this example, I just initiate a &lt;b&gt;DiskPart&lt;/b&gt; set of commands to assign the mounted drive the letter L:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/image_5F00_2ED19891.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/image_5F00_thumb_5F00_0DDE25EA.png" width="575" height="347" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the Windows Explorer window the letter now appears as L: for the &lt;b&gt;WindowsAzureDrive&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;Within approximately 30 seconds (which is the value used in the &lt;b&gt;Run&lt;/b&gt; method by the custom code) &lt;b&gt;VerifyDriveLetter&lt;/b&gt; detects it’s not the intended drive and initiates a change.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/image_5F00_1AD805FB.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/image_5F00_thumb_5F00_328F3D61.png" width="584" height="357" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;And the below image shows the drive again, appearing as the M: drive:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/image_5F00_6342450C.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/image_5F00_thumb_5F00_424ED265.png" width="615" height="371" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;Future Options&lt;/h3&gt;

&lt;p&gt;Since capabilities in the Windows Azure platform change over time the ability to dictate the specific letter to be used may come available. Until then, this approach, by means of the Windows Azure Drive and Virtual Disk Services abstraction provided by the platform offers a means to accommodate codebase and application logic that is dependent upon predetermined drive letters.&lt;/p&gt;

&lt;h3&gt;References&lt;/h3&gt;

&lt;p&gt;[1] Windows Azure Drives &lt;a href="http://www.windowsazure.com/en-us/develop/net/fundamentals/cloud-storage/#drives"&gt;http://www.windowsazure.com/en-us/develop/net/fundamentals/cloud-storage/#drives&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[2] Virtual Disk Service &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb986750(v=vs.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/windows/desktop/bb986750(v=vs.85).aspx&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[3] CloudDrive Storage Client &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storageclient.clouddrive.aspx"&gt;http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storageclient.clouddrive.aspx&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[4] Diskpart.exe &lt;a href="http://technet.microsoft.com/en-us/library/cc770877(v=WS.10).aspx"&gt;http://technet.microsoft.com/en-us/library/cc770877(v=WS.10).aspx&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[5] Task element &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/gg557552.aspx#Task"&gt;http://msdn.microsoft.com/en-us/library/windowsazure/gg557552.aspx#Task&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src="http://cicoria.com/cs1/emoticons/emotion-14.gif" alt="Devil" /&gt; Runtime element &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/gg557552.aspx#Runtime"&gt;http://msdn.microsoft.com/en-us/library/windowsazure/gg557552.aspx#Runtime&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[7] NetFxEntryPoint element &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/gg557552.aspx#NetFxEntryPoint"&gt;http://msdn.microsoft.com/en-us/library/windowsazure/gg557552.aspx#NetFxEntryPoint&lt;/a&gt;&lt;/p&gt;











&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a title="http://cicoria.com/downloads/waz/MountXDriveSameLetter.zip" href="http://cicoria.com/downloads/waz/MountXDriveSameLetter.zip"&gt;Solution File: MountXDriveSameLetter.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://cicoria.com/cs1/aggbug.aspx?PostID=2931" width="1" height="1"&gt;</description><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Utilities/default.aspx">Utilities</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Cloud/default.aspx">Cloud</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Windows+Azure/default.aspx">Windows Azure</category></item><item><title>Viewing the User Token from Visual Studio 2010 Debugger</title><link>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/12/06/viewing-the-user-token-from-visual-studio-2010-debugger.aspx</link><pubDate>Tue, 06 Dec 2011 23:00:58 GMT</pubDate><guid isPermaLink="false">29a00c46-c030-43c5-bbda-4d08b2dd4d56:2930</guid><dc:creator>cicorias</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://cicoria.com/cs1/blogs/cedarlogic/rsscomments.aspx?PostID=2930</wfw:commentRss><comments>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/12/06/viewing-the-user-token-from-visual-studio-2010-debugger.aspx#comments</comments><description>&lt;p&gt;When you’re debugging security related things, sometimes you need to take a look at the thread identities user token.&lt;/p&gt;  &lt;p&gt;When you’re inside of Visual Studio 2010 – in the watch windows you enter ‘$user’&amp;#160; and you’ll get the same as when in windbg with !token –n&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/SNAGHTML6af2ad9_5F00_1D040A08.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="SNAGHTML6af2ad9" border="0" alt="SNAGHTML6af2ad9" src="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/SNAGHTML6af2ad9_5F00_thumb_5F00_150C67A6.png" width="682" height="219" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://cicoria.com/cs1/aggbug.aspx?PostID=2930" width="1" height="1"&gt;</description><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/.NET/default.aspx">.NET</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Troubleshooting/default.aspx">Troubleshooting</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Tricks/default.aspx">Tricks</category></item><item><title>Microsoft TechNet–Create PDF Takeaway chapters for your set of topics–great feature just added..</title><link>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/11/30/microsoft-technet-create-pdf-takeaway-chapters-for-your-set-of-topics-great-feature-just-added.aspx</link><pubDate>Wed, 30 Nov 2011 15:25:14 GMT</pubDate><guid isPermaLink="false">29a00c46-c030-43c5-bbda-4d08b2dd4d56:2929</guid><dc:creator>cicorias</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://cicoria.com/cs1/blogs/cedarlogic/rsscomments.aspx?PostID=2929</wfw:commentRss><comments>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/11/30/microsoft-technet-create-pdf-takeaway-chapters-for-your-set-of-topics-great-feature-just-added.aspx#comments</comments><description>&lt;p&gt;If you’re like me, having those PDF version for offline review are great.&amp;#160; It was a pain before as I had to individually print web pages to single PDF using tools.&lt;/p&gt;  &lt;p&gt;Now, TechNet can track a “book” of topics for you, and then generate HTML or PDF for you to download – personal publishing &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://cicoria.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/wlEmoticon_2D00_smile_5F00_1796848C.png" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.technet.com/b/tonyso/archive/2011/09/13/roll-your-own-techdocs.aspx"&gt;Roll-your-own techdocs for free - TONYSO - Site Home - TechNet Blogs&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://cicoria.com/cs1/aggbug.aspx?PostID=2929" width="1" height="1"&gt;</description><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Tricks/default.aspx">Tricks</category></item><item><title>Dennis Ritchie, Father of C and Co-Developer of Unix, Dies | Wired Enterprise | Wired.com</title><link>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/10/14/dennis-ritchie-father-of-c-and-co-developer-of-unix-dies-wired-enterprise-wired-com.aspx</link><pubDate>Fri, 14 Oct 2011 14:43:19 GMT</pubDate><guid isPermaLink="false">29a00c46-c030-43c5-bbda-4d08b2dd4d56:2928</guid><dc:creator>cicorias</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://cicoria.com/cs1/blogs/cedarlogic/rsscomments.aspx?PostID=2928</wfw:commentRss><comments>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/10/14/dennis-ritchie-father-of-c-and-co-developer-of-unix-dies-wired-enterprise-wired-com.aspx#comments</comments><description>&lt;p&gt;Wow – I still have my &lt;a href="http://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628/ref=sr_1_1?ie=UTF8&amp;amp;qid=1318603382&amp;amp;sr=8-1" target="_blank"&gt;K&amp;amp;R book&lt;/a&gt; from a class I took at AT&amp;amp;T.&amp;#160; Cut my teeth on nix…&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.wired.com/wiredenterprise/2011/10/dennis-ritchie/"&gt;Dennis Ritchie, Father of C and Co-Developer of Unix, Dies | Wired Enterprise | Wired.com&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://cicoria.com/cs1/aggbug.aspx?PostID=2928" width="1" height="1"&gt;</description></item><item><title>Description of Update Rollup 1 for Active Directory Federation Services (AD FS) 2.0</title><link>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/10/13/description-of-update-rollup-1-for-active-directory-federation-services-ad-fs-2-0.aspx</link><pubDate>Thu, 13 Oct 2011 12:57:07 GMT</pubDate><guid isPermaLink="false">29a00c46-c030-43c5-bbda-4d08b2dd4d56:2927</guid><dc:creator>cicorias</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://cicoria.com/cs1/blogs/cedarlogic/rsscomments.aspx?PostID=2927</wfw:commentRss><comments>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/10/13/description-of-update-rollup-1-for-active-directory-federation-services-ad-fs-2-0.aspx#comments</comments><description>&lt;p&gt;Multiple UPN support now available…&lt;/p&gt;  &lt;p&gt;&lt;a href="http://support.microsoft.com/kb/2607496"&gt;Description of Update Rollup 1 for Active Directory Federation Services (AD FS) 2.0&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://cicoria.com/cs1/aggbug.aspx?PostID=2927" width="1" height="1"&gt;</description><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Security/default.aspx">Security</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/ADFS/default.aspx">ADFS</category></item><item><title>Additional Mime Types in Visual Studio 2010 Development Web Server</title><link>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/10/06/additional-mime-types-in-visual-studio-2010-development-web-server.aspx</link><pubDate>Thu, 06 Oct 2011 22:38:51 GMT</pubDate><guid isPermaLink="false">29a00c46-c030-43c5-bbda-4d08b2dd4d56:2926</guid><dc:creator>cicorias</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://cicoria.com/cs1/blogs/cedarlogic/rsscomments.aspx?PostID=2926</wfw:commentRss><comments>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/10/06/additional-mime-types-in-visual-studio-2010-development-web-server.aspx#comments</comments><description>&lt;p&gt;While the development server in Visual Studio 2010 is great for most work, it does have 1 shortcoming in that if you start adding content types that are not part of the base set of known Mime types built in, you won’t affect the proper header response that is emitted to the client/browser.&lt;/p&gt;  &lt;p&gt;For example MP4 files, out of the box the development web server emits application/octet-stream or something like that.&amp;#160; What we really need is video/mp4.&lt;/p&gt;  &lt;p&gt;Now, with IIS Express, you can easily switch over to use that and just add the correct mapping to the section of the web.config when you’re running in integrated mode.&amp;#160; Such as follows:&lt;/p&gt;  &lt;pre class="brush: xml;"&gt;&amp;lt;system.webServer&amp;gt;
  &amp;lt;modules runAllManagedModulesForAllRequests=&amp;quot;true&amp;quot; /&amp;gt;
  &amp;lt;staticContent&amp;gt;
    &amp;lt;mimeMap fileExtension=&amp;quot;.mp4&amp;quot; mimeType=&amp;quot;video/mp4&amp;quot; /&amp;gt;
    &amp;lt;mimeMap fileExtension=&amp;quot;.m4v&amp;quot; mimeType=&amp;quot;video/m4v&amp;quot; /&amp;gt;
  &amp;lt;/staticContent&amp;gt;
&amp;lt;/system.webServer&amp;gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;However, with the Visual Studio 2010 built in Web Development server, you can’t affect the mime type support through configuration. &lt;/p&gt;

&lt;p&gt;For this a simple NuGet package is available that provides a simple HttpModule to affect the ContentType on the response headers.&amp;#160; it reads the Web.config for the site and will honor the section above – this all happens only when NOT running in Integrated Pipeline mode.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/image_5F00_3C0A4A4C.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/image_5F00_thumb_5F00_7448C164.png" width="418" height="49" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/SNAGHTML6f59550_5F00_6C511F02.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="SNAGHTML6f59550" border="0" alt="SNAGHTML6f59550" src="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/SNAGHTML6f59550_5F00_thumb_5F00_5D3A4028.png" width="548" height="274" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sample Solution and Source here: &lt;a href="http://cicoria.com/downloads/SampleMimeHelper.zip"&gt;SampleMimeHelper.zip&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The HttpModule makes use of dynamically loading via the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.preapplicationstartmethodattribute.aspx" target="_blank"&gt;PreApplicationStartMethod&lt;/a&gt; and the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.web.infrastructure.dynamicmodulehelper.dynamicmoduleutility.registermodule.aspx" target="_blank"&gt;DynamicModuleHelper&lt;/a&gt; utility method that is part of the Microsoft.Web.Infrastructure namespace. &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Diagnostics;
using System.Configuration;
using System.Web.Configuration;
using System.Xml.Linq;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;

[assembly: PreApplicationStartMethod(typeof(MimeHelper), &amp;quot;Start&amp;quot;)]

/// &amp;lt;summary&amp;gt;
/// Summary description for MimeHelper
/// &amp;lt;/summary&amp;gt;
public class MimeHelper : IHttpModule
{
    static Dictionary&amp;lt;string, string&amp;gt; s_mimeMappings;
    static object s_lockObject = new object();

    public static void Start()
    {
        if ( ! HttpRuntime.UsingIntegratedPipeline)
            DynamicModuleUtility.RegisterModule(typeof(MimeHelper));
    }

    static string GetMimeType(HttpContext context)
    {
        var ext = VirtualPathUtility.GetExtension(context.Request.Url.ToString());
        if (string.IsNullOrEmpty(ext)) return null;

        CreateMapping(context.ApplicationInstance);

        string mimeType = null;
        s_mimeMappings.TryGetValue(ext, out mimeType);

        return mimeType;

    }

    static void CreateMapping(HttpApplication app)
    {
        if (null == s_mimeMappings)
        {
            lock (s_lockObject)
            {
                if (null == s_mimeMappings)
                {
                    string path = app.Server.MapPath(&amp;quot;~/web.config&amp;quot;);
                    XDocument doc = XDocument.Load(path);

                    var s = from v in doc.Descendants(&amp;quot;system.webServer&amp;quot;).Descendants(&amp;quot;staticContent&amp;quot;).Descendants(&amp;quot;mimeMap&amp;quot;)
                            select new { mimeType = v.Attribute(&amp;quot;mimeType&amp;quot;).Value, fileExt = v.Attribute(&amp;quot;fileExtension&amp;quot;).Value };

                    s_mimeMappings = new Dictionary&amp;lt;string, string&amp;gt;();
                    foreach (var item in s)
                    {
                        s_mimeMappings.Add(item.fileExt.ToString(), item.mimeType.ToString());
                    }
                }
            }
        }
    }


    public void Dispose() { }

    public void Init(HttpApplication context)
    {
        context.EndRequest += new EventHandler(context_EndRequest);
    }

    void context_EndRequest(object sender, EventArgs e)
    {
        try
        {
            HttpApplication app = sender as HttpApplication;
            string mimeType = GetMimeType(app.Context);

            if (null == mimeType) return;

            app.Context.Response.ContentType = mimeType;
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);
        }
    }
}&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://cicoria.com/cs1/aggbug.aspx?PostID=2926" width="1" height="1"&gt;</description><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/.NET/default.aspx">.NET</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Code/default.aspx">Code</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/VS2010/default.aspx">VS2010</category></item><item><title>Faking SPContext–for testing only…</title><link>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/09/21/faking-spcontext-for-testing-only.aspx</link><pubDate>Wed, 21 Sep 2011 21:54:41 GMT</pubDate><guid isPermaLink="false">29a00c46-c030-43c5-bbda-4d08b2dd4d56:2925</guid><dc:creator>cicorias</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://cicoria.com/cs1/blogs/cedarlogic/rsscomments.aspx?PostID=2925</wfw:commentRss><comments>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/09/21/faking-spcontext-for-testing-only.aspx#comments</comments><description>&lt;p&gt;Keith Dahlby has a good post on creating a fake SPContext.&amp;#160; Here’s the link and the code&lt;/p&gt;  &lt;p&gt;NOTE: This is not production safe code – use at own risk…&lt;/p&gt;  &lt;p&gt;&lt;a title="http://solutionizing.net/2009/02/16/faking-spcontext/" href="http://solutionizing.net/2009/02/16/faking-spcontext/"&gt;http://solutionizing.net/2009/02/16/faking-spcontext/&lt;/a&gt;&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;public static SPContext FakeSPContext(SPWeb contextWeb)
{
  // Ensure HttpContext.Current
  if (HttpContext.Current == null)
  {
    HttpRequest request = new HttpRequest(&amp;quot;&amp;quot;, web.Url, &amp;quot;&amp;quot;);
    HttpContext.Current = new HttpContext(request,
      new HttpResponse(TextWriter.Null));
  }

  // SPContext is based on SPControl.GetContextWeb(), which looks here
  if(HttpContext.Current.Items[&amp;quot;HttpHandlerSPWeb&amp;quot;] == null)
    HttpContext.Current.Items[&amp;quot;HttpHandlerSPWeb&amp;quot;] = web;

  return SPContext.Current;
}&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://cicoria.com/cs1/aggbug.aspx?PostID=2925" width="1" height="1"&gt;</description><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/SharePoint/default.aspx">SharePoint</category></item><item><title>Use an Action delegate to time a method…</title><link>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/09/21/use-an-action-delegate-to-time-a-method.aspx</link><pubDate>Wed, 21 Sep 2011 19:15:03 GMT</pubDate><guid isPermaLink="false">29a00c46-c030-43c5-bbda-4d08b2dd4d56:2924</guid><dc:creator>cicorias</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://cicoria.com/cs1/blogs/cedarlogic/rsscomments.aspx?PostID=2924</wfw:commentRss><comments>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/09/21/use-an-action-delegate-to-time-a-method.aspx#comments</comments><description>&lt;p&gt;I wanted an ability to be able to simply time methods and write to a log/trace sink and a very simple approach that I ended up using was to provide a method that takes an Action delegate which would be the method that is to be timed.&lt;/p&gt;  &lt;p&gt;The following is what I came up with (this is my reminder…)&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;class Program
{
    static void Main(string[] args)
    {
        TestMethod1();
    }

    private static void TestMethod1()
    {
        LoggingHelper.TimeThis(&amp;quot;doing something&amp;quot;, () =&amp;gt;
        {
            Console.WriteLine(&amp;quot;This is the Real Method Body&amp;quot;);
            Thread.Sleep(100);
        });
    }
}

public static class LoggingHelper
{
    public static void TimeThis(string message, Action action)
    {
        string methodUnderTimer = GetMethodCalled(1);
        Stopwatch sw = Stopwatch.StartNew();
        LogMessage( string.Format(&amp;quot;started: {0} : {1}&amp;quot;, methodUnderTimer, message));
        action();
        sw.Stop();
        LogMessage(string.Format(&amp;quot;ended  : {0} : {1} : elapsed : {2}&amp;quot;, methodUnderTimer, message, sw.Elapsed));

    }

    private static string GetMethodCalled(int stackLevel)
    {
        StackTrace stackTrace = new StackTrace();
        StackFrame stackFrame = stackTrace.GetFrame(stackLevel + 1);
        MethodBase methodBase = stackFrame.GetMethod();
        return methodBase.Name;
    }

    static void LogMessage(string message){
        Console.WriteLine(&amp;quot;{0}&amp;quot;, message);
    }

}&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://cicoria.com/cs1/aggbug.aspx?PostID=2924" width="1" height="1"&gt;</description><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/.NET/default.aspx">.NET</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Code/default.aspx">Code</category></item><item><title>Comparison of Windows Azure Storage Queues and Service Bus Queues « Microsoft Technologies Rocks !!!</title><link>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/09/20/comparison-of-windows-azure-storage-queues-and-service-bus-queues-171-microsoft-technologies-rocks.aspx</link><pubDate>Tue, 20 Sep 2011 12:06:46 GMT</pubDate><guid isPermaLink="false">29a00c46-c030-43c5-bbda-4d08b2dd4d56:2923</guid><dc:creator>cicorias</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://cicoria.com/cs1/blogs/cedarlogic/rsscomments.aspx?PostID=2923</wfw:commentRss><comments>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/09/20/comparison-of-windows-azure-storage-queues-and-service-bus-queues-171-microsoft-technologies-rocks.aspx#comments</comments><description>&lt;p&gt;Nice table comparing Windows Azure Queues vs. Windows Azure AppFabric Service Bus – note the comment regarding in WAZ SDK 1.5 Queue message size is now 64KB&lt;/p&gt;  &lt;p&gt;Of course, I like the name of the blog too.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://preps2.wordpress.com/2011/09/17/comparison-of-windows-azure-storage-queues-and-service-bus-queues/"&gt;Comparison of Windows Azure Storage Queues and Service Bus Queues « Microsoft Technologies Rocks !!!&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://cicoria.com/cs1/aggbug.aspx?PostID=2923" width="1" height="1"&gt;</description><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Azure/default.aspx">Azure</category></item><item><title>MiniProfiler– A simple but effective mini-profiler for ASP.NET MVC and ASP.NET.</title><link>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/09/18/miniprofiler-a-simple-but-effective-mini-profiler-for-asp-net-mvc-and-asp-net.aspx</link><pubDate>Sun, 18 Sep 2011 13:34:49 GMT</pubDate><guid isPermaLink="false">29a00c46-c030-43c5-bbda-4d08b2dd4d56:2922</guid><dc:creator>cicorias</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://cicoria.com/cs1/blogs/cedarlogic/rsscomments.aspx?PostID=2922</wfw:commentRss><comments>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/09/18/miniprofiler-a-simple-but-effective-mini-profiler-for-asp-net-mvc-and-asp-net.aspx#comments</comments><description>&lt;p&gt;Once in a while a good tool that I find out about that helps me developing solutions comes in real handy.&amp;#160; MiniProfiler is one of those tools.&lt;/p&gt;  &lt;p&gt;Developed by the StackOverflow folks it’s available in source or binary, and NuGet packages&lt;/p&gt;  &lt;p&gt;Take a look&lt;/p&gt;  &lt;p&gt;&lt;a title="http://code.google.com/p/mvc-mini-profiler/" href="http://code.google.com/p/mvc-mini-profiler/"&gt;http://code.google.com/p/mvc-mini-profiler/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a title="http://nuget.org/List/Packages/MiniProfiler" href="http://nuget.org/List/Packages/MiniProfiler"&gt;http://nuget.org/List/Packages/MiniProfiler&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://cicoria.com/cs1/aggbug.aspx?PostID=2922" width="1" height="1"&gt;</description><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/.NET/default.aspx">.NET</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Utilities/default.aspx">Utilities</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/MVC/default.aspx">MVC</category></item><item><title>Slides for BUILD conference…</title><link>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/09/18/slides-for-build-conference.aspx</link><pubDate>Sun, 18 Sep 2011 12:44:56 GMT</pubDate><guid isPermaLink="false">29a00c46-c030-43c5-bbda-4d08b2dd4d56:2921</guid><dc:creator>cicorias</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://cicoria.com/cs1/blogs/cedarlogic/rsscomments.aspx?PostID=2921</wfw:commentRss><comments>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/09/18/slides-for-build-conference.aspx#comments</comments><description>&lt;p&gt;On the Channel 9 site where the BUILD conference sessions are available, there are several feeds that provide the media associated with the sessions.&lt;/p&gt;  &lt;p&gt;One that’s not listed explicitly is the PowerPoint slides – that feed is here:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://channel9.msdn.com/Events/BUILD/BUILD2011/RSS/slides" href="http://channel9.msdn.com/Events/BUILD/BUILD2011/RSS/slides"&gt;http://channel9.msdn.com/Events/BUILD/BUILD2011/RSS/slides&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://cicoria.com/cs1/aggbug.aspx?PostID=2921" width="1" height="1"&gt;</description><category domain="http://cicoria.com/cs1/blogs/cedarlogic/archive/tags/Build/default.aspx">Build</category></item><item><title>Building scalable web applications with Windows Azure (ed. and on premise too!)</title><link>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/09/17/building-scalable-web-applications-with-windows-azure-ed-and-on-premise-too.aspx</link><pubDate>Sat, 17 Sep 2011 16:24:25 GMT</pubDate><guid isPermaLink="false">29a00c46-c030-43c5-bbda-4d08b2dd4d56:2920</guid><dc:creator>cicorias</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://cicoria.com/cs1/blogs/cedarlogic/rsscomments.aspx?PostID=2920</wfw:commentRss><comments>http://cicoria.com/cs1/blogs/cedarlogic/archive/2011/09/17/building-scalable-web-applications-with-windows-azure-ed-and-on-premise-too.aspx#comments</comments><description>&lt;p&gt;Matthew Kerner’s session at BUILD covers many of the patterns and approaches that a well designed and highly scalable solution can do to make the most efficient use of the platform.&lt;/p&gt;  &lt;p&gt;Truth is many of the areas Matthew covers should be for on Premise too – including use of Windows Azure CDN...&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://cicoria.com/cs1/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/cedarlogic/wlEmoticon_2D00_smile_5F00_45B0C56D.png" /&gt;&amp;#160; At about ~30:00 in Matthew references one of my posts on Windows Azure CDN and using it with your Compute role (hosted service) as an CDN origin…&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Building scalable web apps with Windows Azure   &lt;br /&gt;&lt;a title="http://channel9.msdn.com/events/BUILD/BUILD2011/SAC-870T" href="http://channel9.msdn.com/events/BUILD/BUILD2011/SAC-870T"&gt;http://channel9.msdn.com/events/BUILD/BUILD2011/SAC-870T&lt;/a&gt;&lt;/p&gt; &lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://cicoria.com/cs1/aggbug.aspx?PostID=2920" width="1" height="1"&gt;</description></item></channel></rss>
