Jeff Widmer's Blog

ASP.NET, ASP.NET MVC, C#, VB.NET, IIS7, Windows Forms, VB6, ASP 3.0

  • How to get Fiddler to show Azure Service API requests

    How to get Fiddler to show outbound requests such as to the Azure Service APIs:

    Add the following into your web.config:

    <system.net>
      <defaultProxy>
        <proxy autoDetect="false" bypassonlocal="false" proxyaddress="
    http://127.0.0.1:8888" usesystemdefault="false" />
      </defaultProxy>
    </system.net>

    See this post for other ways to set up the proxy but I found this the easiest - http://docs.telerik.com/fiddler/configure-fiddler/tasks/ConfigureDotNETApp

    And then enable Fiddler to decrypt HTTPS traffic:

    image

    Note: Regardless of other settings, .NET will always bypass the Fiddler proxy for URLs containing localhost. So, rather than using localhost, change your code to refer to the machine name.

  • Where’s the SQL Server Configuration Manager in Windows 8?

    The SQL Server Configuration Manager is helpful for stopping/starting the SQL Server Services on your machine and also making sure all of the appropriate connection protocols are enabled.  In particular it really helps when you are running multiple instances of SQL Server since it allows you to view and control all of them from one place. 

    But in Windows 8 and Windows 8.1, the SQL Server Configuration Manager is no longer found in your list of programs and it does not show up when you search (Windows-S) for it by name.  So how do you get to it?

    This article http://technet.microsoft.com/en-us/library/ms174212(v=sql.110).aspx has details on how to get to the SQL Server Configuration Manager:

    To access SQL Server Configuration Manager Using Windows 8, because SQL Server Configuration Manager is a snap-in for the Microsoft Management Console program and not a stand-alone program, SQL Server Configuration Manager not does not appear as an application when running Windows 8. To open SQL Server Configuration Manager, in the Search charm, under Apps, type SQLServerManager11.msc (for SQL Server 2012) or SQLServerManager10.msc for (SQL Server 2008), and then press Enter.

    In SQL Server 2014 the SQL Server Configuration Manager is back in All Programs:

    image

     

    How to get to the SQL Server 2012 Configuration Manager in Windows 8 or Windows 8.1

    Start > Run > SQLServerManager11.msc

    image

  • OneNote Page to PDF without Footer

    A very useful feature of OneNote is that you can Export or Save a page (or section) as a PDF.  I use this for generating invoices for my clients but there are lots of ways quickly turning your OneNote page into a PDF can help your daily workflow. 

    You can create a PDF out of your OneNote page by going to File > Export and then choosing the PDF format from the list of options on the right.

    image

    The exported PDF will include a footer which by default is the OneNote section name and the page number in the PDF:

    image 

    The File > Export dialog does not have a settings section to turn off the footer but you can do this by using the Print Preview dialog which controls the same footer format.

    If you go to File > Print > Print Preview

    image

    The Print Preview Dialog will allow you to control the footer format with several different layout options including one for not including a footer at all.

    image

    Change the footer to “(none)”:

    image

    Close this dialog and now when you Export your OneNote page to a PDF there will be no footer:

    image

    The setting is maintained for the life of your OneNote session but once you close and open OneNote again it is lost and resets to the default which is to include the footer.  In any case it is good to know there is a way to get rid of the footer when exporting your OneNote page as a PDF.

  • Getting Started with Azure Files Preview

    Azure Files allows Virtual Machines (VMs) in an Azure Data Center to mount a shared file system and then these VMs will be able to access these files using standard Windows file APIs (CreateFile, ReadFile, WriteFile, etc.). Many VMs can attach to these files concurrently, allowing you to share persistent data easily between various roles and instances. In addition to accessing your files through the Windows file APIs, you can access your data using the Azure Files REST API.  Below I will take you through getting started with the Azure Files Preview and then end with mounting the Azure Files Share as a drive in your Azure Virtual Machine.  See Introducing Microsoft Azure File Service for a more detailed look at Azure Files.

    To get started with the Azure Files Preview, you will first need to apply for the preview and have it activated on your Azure account.  Start at the Azure Preview features scroll down to the Azure Files section and click the “Try it” button.

    image

    Your account will then be added to the queue to get activated with the Azure Files Preview, and while that sounds like it will take a long time, the email shows about in about 5 minutes saying Azure Files preview has been activated in your Azure account.

    image

    Once your account has been activated with the Azure Files preview, log into the Azure Management Portal and drill down into the Storage feature.

    image

    The Azure Files Preview is added on top of a storage account which means it is kind of hidden that you have the Preview activated on your account until you create a new storage account.  Go ahead and create a new storage account by using the New button.

    image

    IMPORTANT: Mounting the Azure Files share as a drive in a virtual machine requires that you have the Storage Account and Virtual Machine in the same Location.  For example, if you create the storage account in South Central US then the Azure Virtual Machine must also be in the South Central US location.  If you want to mount the Azure Files Share in a preexisting Azure Virtual Machine, make sure the Locations match between both.

    Once the new storage account is provisioned, drill down into it and then click on the Dashboard tab.  Here you will see the new Azure Files Preview is activated on the storage account with an endpoint for the new Azure Files service (https://[storage_account_name].file.core.windows.net/).

    image

     

    Now the fun part begins where you can create shares and add directories and files to your share.  The storage account that you just created contains zero or more Azure File shares.  In each of those shares is where your put your directory and file hierarchy.  You can read more about this from the Microsoft Azure Documentation Naming and Referencing Shares, Directories, Files, and Metadata.

    First thing we’ll do is create a share and the easiest way to do that is through PowerShell and the PowerShell Cmdlets for Files which can be found from reading Introducing Microsoft Azure File Service - How do I install the PowerShell Cmdlets for Files?  From this documentation FAQ, download the zip from http://go.microsoft.com/fwlink/?LinkID=398183 and then make sure to unblock the zip file before extracting.  Now go ahead and extract the files, open a PowerShell console, and change to the folder containing the extracted files.  If everything goes well you will end up with a directory containing the following:

    image

    And your PowerShell console opened to this directory:

    image

    Introducing Microsoft Azure File Service has detailed instructions on using the PowerShell Cmdlet for creating your share and adding directories and files.  To create that first share, you will import the PowerShell module, create a new Azure Storage Context, and then create the share:

    import-module .\AzureStorageFile.psd1
    $ctx=New-AzureStorageContext <account name> <account key>
    New-AzureStorageShare <share name> -Context $ctx

    <account name> is the storage account name that you created earlier.
    <account key> is from the Manage Access Keys dialog for this storage account and can be found by clicking the image button when you are in the Storage Account.

    image

    Now that you have the share created, you can mount it as a drive in an Azure Virtual Machine. 

    IMPORTANT NOTE: You can only mount a share in a Virtual Machine from a Storage Account that is in the same Azure Location as the Virtual Machine.  For instance, when creating the Storage Account if you choose South Central US then your virtual machine will also need to be in the South Central US.

    To mount the share as a drive in your virtual machine, execute the following net use command:

    net use z: \\<account name>.file.core.windows.net\<share name> /u:<account name> <account key>

    image

    Now you will have an X drive on your virtual machine:

    image

    And you can work with the drive just like any other directory and create files:

    image

    image

    Wow! I have 5 TBs of free space!!!

    For programmatic access and access outside of an Azure Virtual Machine you can use Windows Azure Storage Client Library to create and edit shares, directories, files, and metadata which is then all visible to the Azure Virtual Machines.

  • Could not load file or assembly 'System.Web.Http.WebHost'

     

    We ran into this error when deploying a solution from the build server:

    Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

    Since this was a new web server and this solution used Nuget (and Nuget Package Restore) for Web Api, we assumed the Nuget packages needed to be updated but whatever type of updating we tried, we were unable to resolve the issue on the deployed web server.  After all sorts of checking and confirming of installed packages and assemblies, we just deleted the packages folder on the build server (the one created by Nuget Package Restore):

    image

    And then a fresh build solved the problem!

    We are not exactly sure what happened here but most likely Nuget Package Restore had pulled down a newer version of the System.Web.Http.WebHost assembly that was not compatible with our project.  But we are not exactly sure why the Visual Studio project (MSBuild) kept trying to use the newer version instead of the proper version for the project reference.  This project had been upgraded to .NET Framework 4.5 several weeks ago and then rolled back to .NET Framework 4.0 because of a different issue.  This could explain where the incorrect version of System.Web.Http.WebHost came from but why Nuget Package Restore kept the wrong one is unknown and why the project kept building with the incorrect assembly is unknown too. 

    In any case, for anyone that runs into the same issue, delete your packages folder and let Nuget Package Restore pull a fresh set of assemblies.

     

    Full Exception information:
        Exception type: HttpException
        Exception message: Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
       at System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app)
       at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)
       at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context)
       at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context)
       at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)

    Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
       at Global.Application_Start(Object sender, EventArgs e)

  • Microsoft Build (MSBuild) 12

    Did you know that you can install MSBuild to your build and deployment server individually without needing to install Visual Studio?

    You can get MSBuild 12 – aka Microsoft Build Tools 2013 – from http://www.microsoft.com/en-us/download/details.aspx?id=40760.

    Downloading and installing will give you MSBuild.exe in C:\Program Files (x86)\MSBuild\12.0\Bin

    image

    The 64-bit version is located in C:\Program Files (x86)\MSBuild\12.0\Bin\amd64.

  • Update Nuget.exe in.nuget package restore folder

    When upgrading to the latest version of MVC with a build server using Nuget package restore, you may get these errors indicating that Nuget is out of date:

    The schema version of 'Microsoft.AspNet.Mvc' is incompatible with version 2.2.31210.9045 of NuGet. Please upgrade NuGet to the latest version from http://go.microsoft.com/fwlink/?LinkId=213942.
    The schema version of 'Microsoft.AspNet.WebPages' is incompatible with version 2.2.31210.9045 of NuGet. Please upgrade NuGet to the latest version from http://go.microsoft.com/fwlink/?LinkId=213942.

    The links in those errors only point you to the Nuget home page which is confusing because it does not really tell you how to update Nuget.

    From this StackOverflow answer, you can use the Nuget.exe executable and tell it to update itself.  To do this open a command window in the folder where you have the old version of Nuget.exe and execute the command:

    nuget.exe update –self

    image

    Nuget.exe will start, check for the latest version, and update itself if there is a newer version:

    image

  • Web Application Project is configured to use IIS. Unable to access the IIS metabase.

    On a new install of Visual Studio 2013 on Windows Server 2012 R2 I ran into the following error when trying to open a Visual Studio Web Application project:

    image

     

    Even though I am an administrator on the machine, Visual Studio is not running as administrator so it does not have permission to the IIS metabase files.  One solution is to run Visual Studio as administrator.  This works but you can also take ownership of the IIS metabase files to fix this too. 

    Browse to C:\Windows\System32\inetsrv and then double-click the “config” directory to get this warning dialog:

    image

    Do the same for the C:\Windows\System32\inetsrv\config\export directory and also the other directories in C:\Windows\System32\inetsrv.

    Now you will be able to open the Visual Studio Web Application Project without a problem.

    ---------------------------
    Microsoft Visual Studio
    ---------------------------

    The Web Application Project is configured to use IIS. Unable to access the IIS metabase. You do not have sufficient privilege to access IIS web sites on your machine.

    ---------------------------
    OK
    ---------------------------

  • OneNote: Do not show Send To OneNote tool in TaskBar

    OneNote has a Send To OneNote tool which can be helpful but also adds an icon to your TaskBar.  I don’t use it enough (especially on my desktop PC) to always have the Send To OneNote tool running and pinned to my TaskBar, so I like to turn it off.  Whenever I install a new instance of Office, it always takes me forever to figure out how to stop the Send To OneNote tool from running in the TaskBar when OneNote starts up.

    To stop the Send To OneNote tool from showing in the TaskBar, click on the Send To OneNote icon in the TaskBar to bring up the tool:

    image

    And then just uncheck the “Start with OneNote” option at the bottom of the window… that’s it!

    It seems like this should be pretty easy to find but this is not the first time I could not figure it out quickly (yes, I install my OS and Office multiple times a year).

    What makes this confusing is I run Windows Server usually for development and the Send To OneNote tool, which clearly shows in the taskbar icon in Windows 8.1, does not show in Windows Server (at least with the default display options running through remote desktop).

    Under Windows 8.1 you can see the “Start with OneNote” checkbox in the thumbnail:

    Windows 8.1 you can see the “Start with OneNote” checkbox

    Under Windows Server you just get the generic thumbnail icon:

    Windows Server you just get the generic thumbnail

     

    Important: Some articles say you can turn off the Send To OneNote tool by unchecking the “Place OneNote icon in the notification area of the taskbar”.  While this is true and if you uncheck that option you will no longer have the Send To OneNote tool, you then also lose the quick keys such as Windows+Shift+S to grab a screen clipping.  I use the OneNote screen clipping key combination so much that I can’t do without it so turning off the OneNote icon is not acceptable.

    Place OneNote icon in the notification area of the taskbar