Author: devonenote

  • Run IIS in 32-bit mode on a 64 bit machine

    IIS 7 / 7.5 / 8

    On IIS 7 / 7.5 / 8,  configure website or web application to run under 32 bit mode can be configured by opening a command prompt and typing following command and press ENTER.

    %windir%system32inetsrvappcmd set config -section:applicationPools -applicationPoolDefaults.enable32BitAppOnWin64:true

    You can achieve the same goal in IIS Manager by opening the ‘Advanced Settings’ on the application pool binded to the website/web application you want to run under 32 bit mode and change “Enable 32-bit Applications” to True

    Enable 32 bit applications in IIS 7

    Click okay and now the web application or website you configured will run under 64-bit mode always.

    IIS 6

    For IIS6 on Windows Server 2003, configure ASP.NET to run in 32 bit mode on a 64 bit windows server.open a command prompt and type following command and press ENTER.

    cscript //nologo %SYSTEMDRIVE%InetPubAdminScriptsadsutil.vbs set w3svc/AppPools/Enable32bitAppOnWin64 1

    In IIS 6, you cannot run one Application Pool in 32-bit and others in 64-bit. But you can do this on IIS 7 and later as Enable32BitAppOnWin64 can be configured per application pool since IIS 7.  

  • Configure PowerShell to use DotNet 4.0

    You might get following error when you load a snap-in that is written by DotNet 4.0.

    This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

    This is because by default, PowerShell uses DotNet version 2.0 CLR. To use powershell load DotNet 4.0 assemblies, the following settings need to be added in PowerShell.exe.config under C:WindowsSysWOW64WindowsPowerShellv1.0.

    <configuration>
        <startup useLegacyV2RuntimeActivationPolicy="true">
            <supportedRuntime version="v4.0.30319"/>
            <supportedRuntime version="v2.0.50727"/>
        </startup>
    </configuration>

    Note:

    1. Above applies to 64bit windows server 2008 r2. On a 32 bit machine, PowerShell.exe.config can be found at C:windowsSystem32WindowsPowerShellv1.0
    2. Create PowerShell.exe.config if this file is not found.
  • How to run ps1 scripts

    PowerShell scripts are text files with ".ps1" extensions that contain PowerShell commands. Starting with Windows Server 2008, PowerShell is built into the OS. For earlier OS versions, you will need to download PowerShell at Microsoft PowerShell Site and install it.

    To run ps1 scripts, you first need to enable scripts by running:

    Set-ExecutionPolicy RemoteSigned

    Otherwise, you will get this error message:

    File <script> cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

    The most common way to run PowerShell scripts is from Windows PowerShell command prompt. You must specify a path to the script to run it. If the script is in your current folder, then you can run it with:

    .script.ps1

    If the script is in another folder, you need specify the full path:

    c:scriptsscript.ps1

      (more…)

    1. Free ebook: Programming Windows Phone 7

      Microsoft are now giving away the eBook Programming Windows Phone 7 by Charles Petzold.  For detail information of this ebook, view http://blogs.msdn.com/b/microsoft_press/archive/2010/10/28/free-ebook-programming-windows-phone-7-by-charles-petzold.aspx

      You can download a PDF here (38.6 MB).

      And you can download the ebook’s sample code here (5.03 MB).

      untitled

    2. Find Physical Host Name of a Virtual Machine

       

      If the virtual machine is hosted on a Windows Server with Hyper-V and has Integration Service installed, you can look at following virtual machine’s registry to identify the physical host machine.

      HKLMSoftwareMicrosoftVirtual MachineGuestParametersPhysicalHostName

       

      If you use PowerShell, here is a one line script that can indicate host name.

      (Get-Item "HKLM:SOFTWAREMicrosoftVirtual MachineGuestParameters").GetValue("PhysicalHostNameFullyQualified")
    3. [ODBC Driver Manager] Data source name not found and no default driver specified

      If you run osql.exe utility on server that does not have SQL server installed, you might get following error: [ODBC Driver Manager] Data source name not found and no default driver specified.

      This is because osql utility uses ODBC API to communicate to SQL server and SQL ODBC driver is not installed. To fix this, simple download and install SQL Native Client. For example, if you are using the osql.exe from the SQL 2008 (10.0), you should install the SQL Native Client 10.0 from: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=C6C3E9EF-BA29-4A43-8D69-A2BED18FE73C

    4. How Can I Uninstall IE9

      IE9 Uninstalling is done via Windows Update control panel.  Select the view installed updates and then uninstall IE9 via the context menu.

      If you want to uninstall IE9 just because of degraded performance when viewing websites, you can try to turn off GPU rendering which might workaround the performance issue.

      1. In Internet Options, select the Advanced tab,
      2. Under Accelerated graphics, check the Use software rendering instead of GPU rendering checkbox.
      3. Click Apply then OK.
      4. Restart IE9

      (more…)

    5. Grant Permission to DefaultAppPool Identity

      After upgrading web applications to IIS 7.5 on Windows Server 2008 R2, you might get following error.

      Access to the path ‘d:sitecache.txt’ is denied.
      Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
      Exception Details: System.UnauthorizedAccessException: Access to the path ‘d:sitecache.txt’ is denied.
      ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate=”true”/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
      To grant ASP.NET access to a file, right-click the file in Explorer, choose “Properties” and select the Security tab. Click “Add” to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

      (more…)

    6. Make IIS 7.5 application pools run as NETWORK SERVICE

      There is a break change in IIS 7.5 on Windows 7 and Windows Server 2008 R2. The default identity for running an application pool is "ApplicationPoolIdentity".  If you have a web application developed against application pools running with NETWORK SERVICE on IIS6/7, it might break after migrated to IIS 7.5 due to default application pool identity change.

      (more…)

    7. Mixed mode assembly Error After Upgrading to DotNet 4.0

      After upgrading existing DotNet 2.0 or 3.5 application to DotNet 4.0, you might see following error message

      Mixed mode assembly is built against version ‘v2.0.50727’ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

      To fix this issue, put a config file next to your exe called <exename>.exe.config with the following content:

      <configuration>
      <startup useLegacyV2RuntimeActivationPolicy=”true”>
      <supportedRuntime version=”v4.0″/>
      </startup>
      </configuration>

      Or if your exe already has config file, you can just append <startup> element section. To know more detail, check out Mark Miller’s post What is useLegacyV2RuntimeActivationPolicy for?

      Update – 2011/11/15.

      Just hit a similar issue today when I referrence SMO in a DotNet 4 Executable

      Microsoft.SqlServer.Management.Dac.DacException: Unable to install DacInstance. Please verify the components of the application. —> System.IO.FileLoadException: Mixed mode assembly is built against version ‘v2.0.50727’ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

      The solution is same – in app.config file of the executable, add the following settings:

      <configuration>
      <startup useLegacyV2RuntimeActivationPolicy=”true”>
      <supportedRuntime version=”v4.0″/>
      </startup>
      </configuration>