Default proxy settings in .Net configuration files

In environments that provide access to the internet through a proxy .Net Assemblies might fail to access the services located on the internet. An easy way to overcome this is to configure the defaultProxy element  in the .Net configuration file for the assembly.

<configuration>
  <system.net>
    <defaultProxy>
      <proxy usesystemdefault="true"
        proxyaddress="http://192.168.1.10:3128"
        bypassonlocal="true" />
      <bypasslist>
        <add address="[a-z]+\.contoso\.com" />
      </bypasslist>
    </defaultProxy>
  </system.net>
</configuration>

The defaultProxy configuration element accepts an address, credentials an optional bypass list.

The configuration can also be inherited by .Net assemblies providing a COM interface if the defaultProxy is configured in the caller’s configuration file.

Advertisements

Passing MSI options through InstallShield setup files

Often MSI installers are wrapped in a boot strap self extracting executable, like InstallShield does it with a setup.exe.

/v

Passing command line options to the wrapped installer through msiexec.exe is straight forward and can be done on the command line by using the /v option. For InstallShield setup executables the call might look like in this example:

setup.exe /v"MSI_PARAM1=0 MSI_PARAM2=MyStringValue"

Note: MSI parameters need to be upper case, otherwise the installer will not find the parameter value in the session.

MSI log

Forcing msiexec to write a log file can be done again by passing the right option to the /v option of the setup executable.

setup.exe /v”MSI_PARAM1=0 MSI_PARAM2=MyStringValue” /v"/l*v c:\test.log"

Silent install
Forcing msiexec to perform a silent or unattended installation is again done by passing the command with the /v option.

setup.exe /v”MSI_PARAM1=0 MSI_PARAM2=MyStringValue" /v"/l*v c:\test.log" /s /v"/qr"

Converting Linux VMWare VM using MVMC 3.0 PowerShell cmdlets

Converting VMs from VMWare to Hyper-V

The most easiest way to convert a VMWare VM is to use Microsoft Virtual Machine Converter 3.0. It comes in two ways, UI and PowerShell Cmdlets. The latter offers more flexibility, especially when the conversion process needs to be automated. Using MVMC you can either just convert a VM or convert and upload directly into Microsoft Azure.

Enable MVMC PowerShell module

1) cd into C:\Program Files\Microsoft Virtual Machine Converter
2) import-module .\MvmcCmdlet.psd1

This example converts a Linux VMWare VM into a Hyper-V VM using a PowerShell ComdLet

ConvertTo-MvmcVirtualHardDisk -DestinationLiteralPath "c:\temp\debian" -SourceLiteralPath "C:\VMs\Debian\disk1.vmdk" -VhdFormat "Vhd" -VhdType FixedHardDisk

Note: In the example I selected the older Vhd format and FixedHardDisk just because these settings are required when importing to Azure. For simple Hyper-V usage VHDX and Dynamic disk size are also possible certainly.

Now you can just create a new VM in Hyper-V Manager and point to the VHD(x) and the VM is available.

SNAGHTML4976a298

image

Uploading a converted VM into Microsoft Azure

Uploading into Azure means basically to upload the VHD into blob storage which then is taken as a base image you point to when creating a new VM. The easiest way to upload a VHD into a blob store is to use Azure CLI.

A command to create an image of the Linux VHD I used earlier looks like this:

azure vm image create DebianImage –blob-url {blobstoreName}/{imageName} –os Linux "c:\temp\debian\disk1.vhd"

With a Windows Server VHD it’s of course much more convenient and can be done from the MVMC UI directly.

Passing arguments to a Windows service installer class using in installutil

Passing parameters to an implementation of the Installer class of a Windows Service executable when installed by the installutil command line tool is pretty easy.

Simply add each parameter and value to the command line, like:

installutil.exe /param1=val1 /param2=val2 serviceexecutable.exe

Note: The parameter arguments needs to be in front of the executable. Otherwise the values will not be passed to the Installer class context.

The installer class implementation can access the arguments conveniently by the context.parameters collection.

image

Restoring a bacpac database backup in SQL Server

SQL database backup in Windows Azure has become super easy. All you need is a database hosted in Azure and a storage account. You can easily configure backup exports on a daily basis and define how long backups should be accessible. But how to restore such a bacpac backup to you on-prem SQL Server?

In Object Explorer select Databases from the Object tree. Choose Import Data-tier-Application and point to the *.bacpac file you downloaded from Azure earlier.

SNAGHTML50dc70

The wizard is mostly self-explanatory, for instance you can change the database name under which the bacpac package should be restored.

Could not find a base address that matches scheme net.pipe for the endpoint with binding NetNamedPipeBinding – WAS and IIS hosting

In most of the cases the error is indicating a missing host/base address section in the config file of the server.

So, simply add a host section to the services section and the define base addresses for http and net pipe like here:

<services>
   <service name="xxxx">
       <host>
           <baseAddresses>
               <add baseAddress="http://localhost:8000/MyService" />
               <add baseAddress="net.tcp://localhost:8100/MyService" />
               <add baseAddress="net.pipe://localhost/" />

But, you can also host a service that is only providing net pipes binding in IIS and benefit from the Windows Process Activation Service (WAS). Using WAS you let IIS control your service and IIS ensures that the service is running and restarted if necessary, all things you need to address in self hosting.

In the case of WAS services you can spare the above, endpoint protocol bindings are in fact defined in IIS and the subject’s exception message is indicating that the net.pipe protocol is not enabled in in the advanced settings of the IIS application. Most probably only the http protocol is enabled, which is the default. Just add net.pipe to the comma separated list and try to browse the service.

SNAGHTML31f444

Setup Azure Files for IIS

To setup a share in Azure Files straight forward, using a few lines of PowerShell makes it easy.

Assuming you applied to the Azure Files Preview program and received the notification email by the azure team that Azure Files is available for your subscription.

Azure Files will be available for each storage account you create after Azure Files became available.

image

After you’ve created a new storage account, Azure Files is configured and pops up in the service list in the storage dashboard in the Azure portal.

Create a share in PowerShell

It needs two steps to create a share in PowerShell. First you need to setup a storage account credentials object. Then take the credentials object and the name of the share to call the New-AzureStorageShare cmdlet.

param (
    [string]$StorageAccount="",
    [string]$StorageKey="",
    [string]$ShareName=""
)
$ctx = New-AzureStorageContext -StorageAccountName $StorageAccount -StorageAccountKey $StorageKey
$share = New-AzureStorageShare $shareName -Context $ctx

To run the script above you need your storage account, the access key, you can find in the keys section of the storage dashboard in the Azure portal, and the name of the share you want to create.

If that’s done your Azure files share is generally available. The easiest way to access the share is to run a net use command from the command line, like:

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

The command above maps the UNC path \\<account name>.file.core.windows.net\<share name> to a drive named z:. File and directories will be available from this moment on by z:\<share name>

Unfortunately, it’s not possible to access files like this in IIS. Instead, you will receive errors like Authentication failure, Web.Config not accessible or simply a page not found error.

Also, you can’t configure ACLs for the share, what makes it difficult to allow the app pool identity to access the shared directories.

How to prepare the IIS application pool

Let’s say we have a web application that first needs to create images on the share. Also clients should be able to request those images by http.

1) First create a new local system user using the computer management snap-in. Assign storage account name and storage key as password to the new user.

2) Now make the new user the app pool identity of the application pool in IIS.

3) Setup a virtual directory that points to the UNC path of the shared directory.

4) Open the Edit Virtual Directory dialog (select Basic Settings… in right pane), click on Connect as.. and select the new user to connect.

image

5) In the Connect as… dialog configure the specific user and take the same user credentials as for application pool. (I tried the Application user (pass-though authentication) option, but was unlucky to access the files in the browser).

image

Now, you should be able to read/write files to the share from the application and browser clients should also be able to stream resources from the share.