How to create an IIS application pool and web site on Windows 10 with PowerShell and Visual Studio Code

Tasks to create an IIS application pool and web site on Windows 10 with PowerShell and Visual Studio Code:

  • Install the Visual Studio Code plugin PowerShell 0.6.2
  • Create a file iis.configuration.ps1 in Visual Studio Code:

    # Note: When run with the Visual Studio Code PowerShell debugger, make sure you use the "x64" debugger,
    #       else you will get an error: New-WebAppPool : Cannot retrieve the dynamic parameters for the cmdlet.

    Import-Module WebAdministration

    # Create application pools
    New-WebAppPool -Name "myapp.localhost" -Force

    # Create websites
    New-Website -Name "myapp.localhost" -Port 80 -HostHeader "myapp.localhost" -ApplicationPool "myapp.localhost" -PhysicalPath "c:\projects\myapp\web" -Force

        • Create a launch.json in the same folder as the iis.configuration.ps1:

          {
              "version": "0.2.0",
               "configurations": [
                  {
                      "name": "PowerShell",
                      "type": "PowerShell",
                      "request": "launch",
                      "program": "${workspaceRoot}/iis.configuration.ps1",
                      "args": [],
                      "cwd": "${workspaceRoot}/iis.configuration.ps1"
                  },
                   {
                      "name": "PowerShell x86",
                      "type": "PowerShell x86",
                      "request": "launch",
                      "program": "${workspaceRoot}/iis.configuration.ps1",
                      "args": [],
                      "cwd": "${workspaceRoot}/iis.configuration.ps1"
                  }
              ]
          }

          Now you can debug / run the iis.configuration.ps1 file, by hitting F5, make sure you selected “PowerShell” and not “PowerShell x86” on the debug tab:

          image

          How to enable JSON dynamic HttpCompression (gzip) on IIS in Windows 8.

          First check if Dynamic compression is enabled:

           

          image

           

          administration.config

          Open C:\Windows\System32\inetsrv\config\administration.config with notepad and change the httpCompression tag:

           

          image

           

          For IIS 7, also change the urlCompression tag:

          image

           

          ISA Server

          If the dynamic compression is still not working, verify there is no ISA server between the server and the client, if so follow the steps on http://forums.iis.net/t/1168067.aspx

          To check if the ISA server is the problem just open a browser on the server en connect to the localhost url, check with fiddler if the dynamic compression works.

          Shifting to express products like Microsoft IIS Express 8 and Microsoft SQL Server 2012 LocalDb for development.

          Most express products have some things in common:

          – Contain the same features as the full product (except for some limitations like, no more then 4GB memory or no more then 10 users etc.)

          – Free of charge

          – Lightweight

          – User profile specific (multiple users on one machine have independent product configuration and processes)

          These products are created mainly for development purposes.

           

          Advantages

          More and more I am shifting to these express products for the O in OTAP and for the build servers, because these products have the following advantages:

          – Free of charge.

          – No configuration.

          – Fast and lightweight installation.

          – Performance improvements for DEV en build server machines.

          – Build servers can use clean instances to run integration tests.

          – Easily to restore to new instance.
          When a per user instance is corrupted it’s very easy to restore it.

          Multiple users can work on one virtual machine, without interfering with each other.
          So each developer can change all the things he or she wants to research some new code, without breaking a shared instance of IIS or SQL Server.

           

          Of course for the T, the A and P in OTAP, I use the full products.

          How to dynamically switch between IIS Express and full IIS in Microsoft Visual Studio 2010 by using a csproj.user file.

          If you want to give every developer the choice to use IIS Express or full IIS during development in Microsoft Visual Studio 2010 sp1, you can use a csproj.user file for you project. This file can be used to overwrite settings in the *.csproj file.

          This file will by default not be added to TFS, so every developer can use it’s own configuration, without interfering with other developers.

          First uncheck "Apply server settings to all users (store in project file)"

          Then check "Use IIS Express" on the Web tab from the Microsoft Visual Studio 2010 sp1 project.

          image

           

          Change the generated *.csproj.user, like:

          <?xml version="1.0" encoding="utf-8"?>
          <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
          <PropertyGroup>
          <ProjectView>ShowAllFiles</ProjectView>
          <UseIISExpress>true</UseIISExpress>
          </PropertyGroup>
          <ProjectExtensions>
          <VisualStudio>
          <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
          <WebProjectProperties>
          <StartPageUrl>Default.aspx</StartPageUrl>
          <StartAction>SpecificPage</StartAction>
          <AspNetDebugging>True</AspNetDebugging>
          <SilverlightDebugging>False</SilverlightDebugging>
          <NativeDebugging>False</NativeDebugging>
          <SQLDebugging>False</SQLDebugging>
          <ExternalProgram>
          </ExternalProgram>
          <StartExternalURL>
          </StartExternalURL>
          <StartCmdLineArguments>
          </StartCmdLineArguments>
          <StartWorkingDirectory>
          </StartWorkingDirectory>
          <EnableENC>False</EnableENC>
          <AlwaysStartWebServerOnDebug>True</AlwaysStartWebServerOnDebug>
          <UseIIS>True</UseIIS>
          <AutoAssignPort>False</AutoAssignPort>
          <DevelopmentServerPort>1000</DevelopmentServerPort>
          <DevelopmentServerVPath>/Test</DevelopmentServerVPath>
          <IISUrl>http://localhost:1000/Test</IISUrl>
          <NTLMAuthentication>False</NTLMAuthentication>
          <UseCustomServer>False</UseCustomServer>
          <CustomServerUrl>
          </CustomServerUrl>
          </WebProjectProperties>
          </FlavorProperties>
          </VisualStudio>
          </ProjectExtensions>
          </Project>
          

          Now your build server can use the settings in the csproj file and you, as a developer, have the choice to use these settings or overwrite them with the *.csproj.user file.

          Solving: Windows Authentication fails, when using a host header and accessing IIS on the local box.

          If you are developing an ASP .NET website that uses Windows Authentication and add a host header in IIS to the ASP .NET web application, accessing the site on the local box, might not work. Windows Authentication will fail if the loopback check is not disabled. By default, loopback check functionality is turned on in Windows Server 2003 SP1 and later. So if you add an entry to the Windows hosts file, found in [C:\Windows\System32\drivers\etc], like:

          127.0.0.1     dev.com

          And access the ASP .NET web application on the local box, by using the hostheader: http://dev.com/MyWebApplicaiton/Default.aspx make sure the loopback check is disabled:

           

          1. Click Start, click Run, type regedit, and then click OK.
          2. Locate and then click the following registry subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
          3. Right-click Lsa, point to New, and then click DWORD Value.
          4. Type DisableLoopbackCheck, and then press ENTER.
          5. Right-click DisableLoopbackCheck, and then click Modify.
          6. In the Value data box, type 1, and then click OK.
          7. Exit Registry Editor.
          8. Restart the computer. Note You must restart the server for this change to take effect

           

          image

          Solving: HttpContext.Current.User.Identity.Name is empty, when using Windows Authentication.

          If you want to use Windows Authentication in your ASP .NET website, you need to add the <authentication mode="Windows"/> tag in the Web.config.

          <system.web>
          <authentication mode="Windows"/>
          

          If the HttpContext.Current.user.Identity.Name is still empty. Check the authentication feature of the web application in IIS, make sure all authentication mechanisms are Disabled, except for the Windows Authentication, this should be set to Enabled.

           

          image

           

          image

          Solving Unable to generate a temporary class error CS2001 en CS2008

           

          Error

           

          System.InvalidOperationException: Unable to generate a temporary class (result=1).
          error CS2001: Source file &#39;C:\Windows\TEMP\beo4ycyh.0.cs&#39; could not be found
          error CS2008: No inputs specified
          at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
          at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
          at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
          at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
          at System.Web.Services.Protocols.XmlReturn.GetInitializers(LogicalMethodInfo[] methodInfos)
          at System.Web.Services.Protocols.HttpServerType..ctor(Type type)
          at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
          at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

           

          Solution

          After adding the application pool service account to the local administrators group, this error was resolved.

          We are now looking into a real solution Winking smile

          Solving: Could not load file or assembly ‘App_Web_squ1ikqu, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified in .NET 4.0

          After we virtualized a production machine and booted this virtualized machine, .NET reported some errors after re-registering .NET 4.0 on IIS7 these error where resolved, but one WCF service kept on logging the error:

          Could not load file or assembly ‘App_Web_squ1ikqu, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified.

           

          Solution

          The error was resolved after stopping all application pools in IIS7 and deleting the temporary internet files in the following folders:

          • C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
          • C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
          • C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files
          • C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files

          Determine the correct w3wp.exe process ID, to attach the Microsoft Visual Studio debugger to, by using the Windows Task Manager

          If you have multiple application pools started in IIS 7 and you want to determine which w3wp.exe process to attach the Microsoft Visual Studio 2010 debugger to, you can use the Microsoft Windows Task Manager.

          Start the Microsoft Windows Task Manager: press [Ctrl + Shift + Esc].

          Add the columns "PID" and "Command Line" to the Process tab.

          image

           

          The name of the application pool will be shown in the Command Line Column.

          In this case the WCF service I wanted to debug, was running on the default [ASP.NET v4.0] application pool.

          The Microsoft Windows Task Manager, shows the PID of this w3wp.exe processes as 8188, so now I can attach the Microsoft Visual Studio debugger, to the process with ID 8188, to start debugging the WCF service