Category: Windows

  • Visual Studio .NET Framework, This site can’t provide a secure connection (ERR_SSL_PROTOCOL_ERROR)

    Visual Studio .NET Framework, This site can’t provide a secure connection (ERR_SSL_PROTOCOL_ERROR)

    This is a problem with the SSL (Secure Sockets Layer) protocol, which is used to establish secure connections between a web server and a browser.

    Solution that worked for me

    1. In Solution Explorer, click your project.
    2. Hit the F4 key (view properties).
    3. Copy the URL (NOT the SSL URL).
    4. Paste the URL into the Project Url on the Web Tab, Save.
    5. In Solution Explorer, click your project.
    6. Hit the F4 key (view properties).
    7. Change SSL Enabled to false.
    8. Change it back to true. There should be a new SSL URL. Copy it.
    9. Paste the new SSL URL into Project URL on Web tab. Click Create Virtual Directory.
    10. Click Override application root URL, and paste in SSL URL. Save.
  • Update Windows Subsystem for Linux

    Update Windows Subsystem for Linux

    The Windows Subsystem for Linux (WSL) lets developers install a Linux distribution and run it inside Windows. I use WSL all the time when working with Windows. It is a handy tool that gives power of Linux and bash without having to change systems. Recently I noticed that I have not updated distro on the Subsystem. It runs the same orginal distro that I installed when I configured my Windows Machine. But luckily updating it is quite straight forward. So, here it comes in case you need to do it:

    In general, the process for upgrading Ubuntu on WSL is pretty much the same as from a “normal” Ubuntu CLI.

    1. First run get your current distro to the latest:

      sudo apt update && sudo apt full-upgrade

      2. Restart your WSL:

      View the list of distros and their current state:

      wsl.exe -l -v
      

      Shutdown everything: 

      wsl.exe --shutdown
      

      Or Terminate a specific distro: 

      wsl.exe -t <DistroName>

      3. Run Distro Update

      Start again terminal and load WSL, then run

      sudo do-release-upgrade

      Once the update has done it’s magic you can reload your terminal and you should have the latest linux distro running.

      There is also another approach if you don’t care about packages you have installed on your distro you can always completely remove a Linux distro on WSL and install new onne, use these steps:

      • Open Settings on Windows 11.
      • Click on Apps.
      • Click the Installed apps page (or Apps and Features)
      • Select the Linux distro, open the menu (three-dotted button) on the right side, and choose the “Uninstall” option.
      • Then go to Windows Store and install new distro

    1. Delete all rows on the table that are older than 100 days

      Delete all rows on the table that are older than 100 days

      USE Database_name;
      DELETE FROM Table_name
      WHERE Date_column < GETDATE() - 100
    2. Fix broken permissions on Windows Server (or desktop)

      Fix broken permissions on Windows Server (or desktop)

      Ever see The “Failed to Enumerate Objects in the Container. Access is denied.” error? I get this sometimes on Windows when pulling code from Git.

      Here is quick fix:

      1. Open PowerShell as Administrator
      2. Run
        takeown /F C:\fullpathToTheFolder
        takeown /F C:\fullpathToTheFolder /r /d y
        icacls C:\fullpathToTheFolder /grant Administrators:F
        icacls C:\fullpathToTheFolder /grant Administrators:F /t
      3. Then open File Explorer normally and you should be able to set permissions normally again.
    3. Benefits of updating from .NET Framework to .NET 6

      Benefits of updating from .NET Framework to .NET 6

      Microsoft’s .NET Core is already several years old but I have not fully embrace it until release of .NET6 last year. Although, I was using .NET Core for smaller projects like Azure Functions and API’s when creating full scale Web Applications I was still favoring ASP.NET MVC in the Framework. But no more! Now for me it is time to say good bye to .NET Framework after ~20 years of great service and move to the next chapter.

      What’s the difference

      Microsoft .NET Framework was released in 2000 to help Windows developers to catch up with web development. Initial release was introducing new language C#, new way of communicating with data XML and Web Services and much more. From 2000 the framework was evolving year by year until to the release 4.8. Microsoft .NET Framework is built around Windows Operating System and it is not very scalable when thinking today’s cloud thinking. Therefore clever guys and girls in Microsoft jump back to drawing board and designed successor for the framework. .NET Core is the latest version of Microsoft’s .NET Framework( The framework is a re-usable design platform for software systems, which provides support for code libraries and various scripting languages ), which is a free, open-source, general-purpose programming platform. It’s a cross-platform framework that works with Windows, Mac OS X, and Linux.The.NET Core Framework may be used to create a variety of apps, including mobile, desktop, online, cloud, IoT, machine learning, microservices, games, and more. .NET Core is written from scratch to make it a modular, lightweight, fast, and cross-platform Framework.

      Why should you update

      Why should you not update

      • The Applications require technologies like workflow, webforms or WCF that are not present in .NET Core.
      • Applications are built to run on Windows alone.

      More at https://dotnet.microsoft.com/

    4. Howto count files in folders by file extension using PowerShell

      Howto count files in folders by file extension using PowerShell

      Use Measure-Object to count things. In this case it would look like:

      Only Files

      Get-ChildItem c:\MyFolder -Recurse -File | Measure-Object | %{$_.Count}
      

      Only Folders

      Get-ChildItem c:\MyFolder -Recurse -Directory | Measure-Object | %{$_.Count}
      

      Both

      Get-ChildItem c:\MyFolder -Recurse | Measure-Object | %{$_.Count}

      Specific files

      Get-ChildItem -Path c:/MyFolder -Recurse -filter *.xml | Measure-Object -Property Directory
      
    5. Making WordPress fast(er) on Azure App Service

      Making WordPress fast(er) on Azure App Service

      I noticed that WordPress and WordPress Multisite on Azure does not perform well. It seems that anything written in PHP is not the first class citizen on Azure and PHP runtime as well as MySQL behaves differenly on Azure than running it on VM or Docker.

      I was not able to make WordPress as fast as it would be on VM but I got close. Please notice that I am running App Service under Windows Operating System. If you have change to run this under Linux you will likely get much better performance and some of the tips below may not be relevent for you. In any case fine tuning these settings are always solution specific but if you have performance problems I hope my findings helps you.

      Step 0 – App and SQL plans

      App Service
      You should run the App Service in minimum P1V2. Everything smaller in a bigger solution becomes slower. This gives 210 total ACU 3.5 GB memory for the app.

      Azure Database for MySQL server

      Gen 5 with 100 GB and 4 cores seemed to work for me. I noticed that there was not much of difference if you choose Basic with 2 vCores. If you don’t need large storage I recommend trying out Basic first but notice that you cannot scale from Basic to General Purpose with a click of a button. It requires moving db’s manually.

      Step 1 – App Service Settings

      Changes Made: 

      • PHP version 7.4
      • Set the Platform as 64 bit
      • Set HTTP-version to 2.0
      • Set the site to ‘Always on
      • Turn Off the Affinity Cookie

      Step 2 – Extend PHP.INI

      Open the solution in Kudu or FTP client and create new folder at d:\home\site\ini on your app structure. Under new ini -folder create settings.ini and add following settings:

      wincache.maxfilesize=1024M
      memory_limit=2048M
      upload_max_filesize=50M
      post_max_size=50M
      max_execution_time=3600
      max_input_time=300
      output_buffering = Off;

      wincache.maxfilesize
      – Defines the maximum allowed size (in kilobytes) for a single file to be cached.

      memory_limit=2048M
      – This sets the maximum amount of memory in bytes that a script is allowed to allocate.

      upload_max_filesize, post_max_size, max_execution_time, max_input_time
      – You may not need this. I got some bigger file execution operations in relation to a WP plugin that required extend size and execution times. Not exactly related to performance.

      output_buffering
      – I don’t really understand why this is set on Azure. App seems to run better if it is disabled?

      After adding the settings.ini under d:\home\site\ini\ folder open App Service > Configuration > Application Settings and the folder to the key called PHP_INI_SCAN_DIR=d:\home\site\ini\ like this:

      Save and restart the App Service. Now you should have custom INI for your app where you can adjust default PHP settings.

      You can verify that your settings are correct by creating phpinfotest.php with <?php phpinfo(); ?> in it and uploading it to the webroot. Then on your browser you can see this file and see all your settings.

      Redis Object Cache and App Service Local Caching

      I have tried both of these and neither them helped me but it might help on some installations. So I will write few words about them

      App Service Local Caching

      The Azure App Service Local Cache feature provides a web role view of your content. This content is a write-but-discard cache of your storage content that is created asynchronously on-site startup. When the cache is ready, the site is switched to run against the cached content. Enabling local caching will change how the storage works for your app service. This is only recommended for more static WordPress instances and not for WordPress instances that have new posts or pages.

      To enable it add these settings to your application settings

      WEBSITE_LOCAL_CACHE_OPTION Always
      WEBSITE_LOCAL_CACHE_SIZEINMB 2000

      I have heard and read this is great setting on some solutions but for me performance got 10 x worse with local caching. So I drop it.

      Redis Object Cache

      Object caching allows your web application to cache the results of queries as objects in low latency memory based storage. But this is also something that may not work for your solution. I did not have good luck on my solution, on my instance speed got 10-15% slower after enabling Redis. There are a few caveats to using the Redis Object Cache approach on WordPress. The caching mechanism does not work well if you have a lot of plugins and themes installed. This is due to the fact that all their data would need to be cached as well with Redis. But it is worth of testing since Azure Cache for Redis is easy to setup and test it. If you don’t see benefits on it you can just delete it. I followed this blog post to configure caching with Redis.

      If you have a lot of visitor on the site I think you should definetly evaluate Redis.

      Cache Plugins for WordPress

      I tested different cache plugins that work with WordPress Multisite and I settled with WP Super Cache. This plugin is simple and quick to configure. If you install the plugin and just enable it it works. Only custom setting I added was in the advanced section I extended cache recycling to 1 hour.

      Azure Content Delivery Network (CDN)

      Azure Content Delivery Network (CDN) lets you reduce load times, save bandwidth and speed responsiveness. You can use the same cache plugin WP Super Cache to enable CDN.

      Other tips

      A few tips to improve WordPress performance and overall settings on Azure Web App are listed below:

        <requestFiltering>
          <denyUrlSequences>
            <add sequence="xmlrpc.php" />
          </denyUrlSequences>
        </requestFiltering>
      • Add .woff mimetypes
          <staticContent>
            <mimeMap fileExtension="woff" mimeType="application/font-woff" />
            <mimeMap fileExtension="woff2" mimeType="application/font-woff2" /> 
              <remove fileExtension=".mp4" />
              <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
              <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
           
          </staticContent>

      Summary

      It is possible to get decent performance on WordPress solutions on App Service but I am still in doubt if this is the better solution than running on Virtual Machine or in the container. I never was able to get close to performance that I can get on Virtual Machine with dedicated application server and MySQL server under Linux. Although, Azure is getting better and faster everyday and there is no doubt that eventually it will be at least as fast as VM.

    6. From AzureRM to AZ

      The Az PowerShell module has been for a while the recommended PowerShell module for interacting with Azure. Here is the quick guide how to install AZ on Windows 10.

      Powershell script to un-install Azure/AzureRM and install AZ

      # Remove base modules:
      uninstall-module Azure
      uninstall-module AzureRM
      
      # Remove the rest
      $Modules = Get-Module -ListAvailable | Where {$_.Name -like 'AzureRM.*'}
      Foreach ($Module in $Modules) {Uninstall-Module $Module}
      
      # Install AZ
      if ($PSVersionTable.PSEdition -eq 'Desktop' -and (Get-Module -Name AzureRM -ListAvailable)) {
          Write-Warning -Message ('Az module not installed. Having both the AzureRM and ' +
            'Az modules installed at the same time is not supported.')
      } else {
          Install-Module -Name Az -AllowClobber -Scope AllUsers -Force
      }
      
      
      # Connect to Azure with a browser sign in token
      Connect-AzAccount

      Further reading

      Build your skills with Microsoft Learn

      Other Azure PowerShell modules

    7. Tip of today: Windows Server restart on given time

      How to Schedule a Reboot. This should work also on workstation.

      This will restart in 6 hours

      Invoke-Command -ComputerName NameOfServer {shutdown /r /t 21600}

      This will restart in 1 hour

      Invoke-Command -ComputerName NameOfServer {shutdown /r /t 3600}

      This will restart in 19th of October 2025 at 12:00 hour

      schtasks /create /tn “Scheduled Reboot” /tr “shutdown /r /t 0” /sc once /st 12:00:00 /sd 19/10/2025 /ru “System”

    8. Reset IIS Application Pool Remotely in PowerShell

      $server = “YOURSERVERNAME”
      $password = “yourpassword”
      $username = “yourusername”
      Write-Host “Start reset”

      $SecurePassword = $password | ConvertTo-SecureString -AsPlainText -Force
      $cred = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $SecurePassword
      $Session = New-PSSession -ComputerName $server -Credential $cred

      Invoke-Command -Session $Session -ScriptBlock {
      Restart-WebAppPool YourAppPoolName
      Write-EventLog -LogName Application -Source MyScript -EventId 3001 -Message “AppPool restart was called from remote”
      }

      Write-Host “Reset done”