IT Nota

  • Home
  • How To
  • .NET
  • WordPress
  • Contact

How to Migrate IIS Websites to a Different Server

Setting up a website on IIS is very easy to do. However, it can get very tedious when we have to migrate multiple IIS websites to a new server. For a really brand new server, the easiest to migrate all those settings of course is to clone the server and then we can reconfigure the IP addresses for each web instance from IIS on the new server. But what if that option is not possible?

In this post, we’ll discuss two ways to migrate multiple IIS websites from one server to another. Ideally, this is done to an imaged server that does not have any websites set up yet. Otherwise, more tweaking is needed so we do not override the already existing sites on the new server.

Method 1: Using Shared Configuration in IIS

This method is the simplest to implement, but only use this if you have a brand new server. DO NOT use this method when migrating websites in addition to an already existing website (or websites) on the destination server.

Please be aware though if you migrate websites from one version of IIS to a newer one, the process can be messy but doable as long as you’re aware of all the gotchas.

  1. Launch IIS Manager and click on the main server node and click on Shared Configuration.

    IIS Shared Configuration

  2. In Shared Configuration screen, click the Export Configuration link.

    IIS Export Configuration option

  3. In the Export Configuration window, enter a Physical Path where you want the configuration files stored. Make sure whichever path you use, it’s an existing folder. Otherwise, you will get an error message that the path does not exist.

    Enter a strong Encryption keys password then click OK.

    IIS Configuration encryption keys password

  4. Check your export configuration folder, there should be three files created for you:

    1. administration.config
    2. applicationHost.config
    3. configEncKey.key

    IIS migration files export folder

  5. Copy all three files to the new server.

  6. Launch IIS Manager on the new server and click on Share Configuration.

    IIS Shared Configuration

  7. This time, check on the Enable shared configuration option and type in all required information to import the configuration from the first server. Click on Apply after you’re done.

    IIS Enable Shared Configuration Import - Physical path

  8. Optional: Typically you don’t need to user User name and Password, unless if you need your credential to access the Physical path where you store the export files. In this case, you can type in your user name (NTID or a service account) and password.

    IIS Enable Shared Configuration with username and password

  9. After clicking Apply link from either step 7 or step 8 (not both), you will be asked to enter your Encryption Keys Password you entered from step 3.

  10. If you entered the correct Encryption Keys Password, you’ll see a notice such as this:

    IIS Enable Shared Configuration notice

    Your existing IIS encryption keys will be backed up in the current configuration directory on your local computer. To restore these keys at a later time, turn off shared configuration.
    

    Just click the OK button.

  11. Finally, you’ll see a succesful message below:

    IIS Enable Shared Configuration successfully saved

    The changes have been successfully saved.
    
    You must close and reopen IIS Manager for it to recognize the configuration changes that you have made.
    

    Just click OK button again.

  12. Close and reopen IIS Manager to see the changes take effect.

That’s it.

Method 2: Using AppCmd.exe

From the Microsoft’s own documentation:

AppCmd.exe is the single command line tool for managing IIS 7 and above. It exposes all key server management functionality through a set of intuitive management objects that can be manipulated from the command line or from scripts.

One of the things you can do with AppCmd is to search, manipulate, export, and import IIS and ASP.NET configuration and configure application pools. So with that, what are the steps to migrate websites to a different server?

  1. From the server where you want to export all the websites, launch Command Prompt and type the following:

            C:\> %windir%\System32\inetsrv\appcmd list apppool /config /xml > C:\Temp\AppPools.xml
            
  2. This command exports all Application Pools in the server, so if you never delete the default ones, you might run into an issue when importing them to the new server. It’s harmless but at some point, you will need to delete them before you can successfully import it.

  3. Once we completed exporting the Application Pools, we still need to export the website settings separately.

    Back in Command Prompt, type in the following:

            C:\> %windir%\System32\inetsrv\appcmd list site /config /xml > C:\Temp\Websites.xml
            
  4. Copy the two XML files to the new server. As an example here, the assumption here is the files are copied to the same folder on the new server (C:\Temp).

  5. On the new server, launch Command Prompt and type the following:

            C:\> %windir%\System32\inetsrv\appcmd add apppool /in < C:\Temp\AppPools.xml
            
  6. If successful, you can right away import the websites by typing the following still in the Command Prompt:

            C:\> %windir%\System32\inetsrv\appcmd add site /in < C:\Temp\Websites.xml
            

That’s all there is to it. You might still need to do some adjustments in terms of changing the IP addresses etc. But at least the bulk majority of the settings are already transferred and doing it this way will save you a lot of time instead of doing it one by one.

Further Reading

How do you migrate an IIS 7 site to another server?
Exporting & Importing App Pools and Websites configuration between multiple IIS instances
Getting Started with AppCmd.exe
How to Get Application Pool Identity Password With AppCmd

August 18, 2021 Filed Under: How To Tagged With: IIS, Internet Information Services, Microsoft, Windows Server

How to Customize 401 Error Page with 302 Redirect on IIS

Continuing from the last post on customizing 401 error page on IIS, there’s a different way to do so by using 302 Redirection.

Using this method is actually a bit more simple to do, it’s just that you have to create a second website with a landing page to serve as your error page. Not everyone has this privilege to just have a second instance created in production environment, so it’s always good to have more options.

When you need to restrict access to your web application on IIS, any unauthorized users will see the standard 401 Error Page from IIS:

401 – Unauthorized: Access is denied due to invalid credentials. You do not have permision to view this directory or page using the credentials that you supplied.

Server Error 401

Instead of serving a default 401 Error Page, it’s always good to show a customized 401 page that is more user-friendly. Here’s a one way to do it by using a page redirect.

Steps to Use Custom 401 Error Page using 302 Redirect in IIS

  1. Create an HTML page as our custom 401 page. In this example, it will be called ITNOTA-Custom-401.htm.

    Simple custom 401 error page in HTML

  2. Create an instance in IIS just for this file and set this file as the main landing page (or use it as your index.htm). For this example, we’ll set this up as fwd.itnota.com with a file name of ITNota-Custom-401.htm.

  3. Next, launch Internet Information Services (IIS) Manager and click on your site on the left pane.

  4. Click on Error Pages.

    IIS Site Error Pages Settings

  5. On the next screen, you will see a list of default error pages according to its Status Code. In this example, we want to select 401.

    IIS Site Error Page 401

  6. On the Edit Custom Error Page window, click on the Respond with a 302 redirect radio button and type in the URL of the second website where your custom 401 page resides, including the file name, then click OK.

    IIS Custom 401 Error Page using 302 Redirect

That’s all there is to it.

As a test, we can try to load the page and this is also where using 302 redirect is different than using a static page within the same instance. If using Windows Authentication, you will not see the Windows Security screen to enter your NTID and password. It does the authentication in the background and if you’re not authorized, you will right away be redirected to the second web page that hosts the 401 custom page.

IIS Render Custom 401 Error Page HTML

Yes, it’s almost like an anti-climax to see a plain custom 401 error page being displayed. I hope you can come up with a much better design than my example to make all the effort worthwhile.

This setting for a custom 401 using 302 redirect works for both ASP.NET and Classic ASP.

Further Reading

How to Use Custom 401 Error Page on IIS
How to Fix Access Denied (401) Error in Microsoft IIS

June 30, 2021 Filed Under: How To Tagged With: IIS, Internet Information Services, Microsoft, Windows Server

How to Use Custom 401 Error Page on IIS

When you need to restrict access to your web application on IIS, any unauthorized users will see the standard 401 Error Page from IIS:

401 – Unauthorized: Access is denied due to invalid credentials. You do not have permision to view this directory or page using the credentials that you supplied.

Server Error 401

Often times, though, you want to show your end users a custom error page with specific instructions on what to do. That is certainly a more graceful way of handling the error than just showing the standard windows 401 error page.

If you have the flexibility to setup your own web instances, you might want to try using 302 Redirect instead as it’s much simpler to setup. Otherwise, this is also a viable option, although a bit long.

Steps to Use Custom 401 Error Page in IIS

  1. Create an HTML page as our custom 401 page. In this example, it will be called ITNOTA-Custom-401.htm.

    Simple custom 401 error page in HTML

    For simplicity, we’ll save the file in C:\Temp folder.

  2. Next, launch Internet Information Services (IIS) Manager and click on your site on the left pane.

  3. Click on Error Pages.

    IIS Site Error Pages Settings

  4. On the next screen, you will see a list of default error pages according to its Status Code. In this example, we want to select 401.

    IIS Site Error Page 401

  5. On the Edit Custom Error Page window, click on the Set… button.

    IIS Edit Custom Error Page

  6. Under Set Localized Custom Error Path window, type in the location where the custom 401 HTML page resides in the Directory path box. Only type in the path/folder. The file name itself should be in the Relative file path textbox, then click OK.

    Set localized Custom Error Path in IIS

  7. You should see something similar to this. Click OK again.

    Edit Custom Error Page file path

  8. At this point, we’re done setting up the custom 401 error page. However, unless if you still use the default for other settings, you may run into this error:

            HTTP Error 500.19 – Internal Server Error
            Absolute physical path "c:\temp" is not allowed in system.webServer/httpErrors section in web.config file. Use relative path instead.
            

    IIS Internal Server Error 500.19

    If you read the error message, it points exactly at the problem in the configuration, that is in the system.webServer/httpErrors section.

  9. In IIS Manager, click on the server on the left navigation pane and click on Configuration Editor

    IIS Configuration Editor - Server level

  10. In the Configuration Editor, under Section:, click on the drop-down and select system.webServer, then httpErrors.

    IIS Configuration Editor system.webServer/httpErrors

  11. Click on allowAbsolutePathsWhenDelegated, then click on the Unlock Attribute if it’s locked. If it’s already unlocked (no padlock sign), then you’re good. Then click Apply under Actions.

    IIS Configuration Editor allowAbsolutePathsWhenDelegated unlocked

  12. Now, click on your site on the left pane of navigation, and also click on Configuration Editor.

    IIS site-level Configuration Editor

  13. Repeat the step to get to the system.webServer/httpErrors and set allowAbsolutePathsWhenDelegated to True. Then, click Apply.

    IIS Configuration Editor allowAbsolutePathsWhenDelegated set to True

  14. At this point, depending on your Authentication setting, you should be able to see the custom 401 error page in your browser (if you failed to authenticate). However, if you use Windows Authentication, you might see a 401.2 error page.

            HTTP Error 401.2 - UnauthorizedYou are not authorized to view this page due to invalid authentication headers.
            

    IIS Error 401.2 - Unauthorized

    Rest easy, we just need to redirect this 401.2 error to our custom 401 error page.

  15. Go back to Internet Information Services (IIS) Manager and click on your site on the left
    and Error Pages on the right.

    IIS Site Error Pages Settings

  16. This time, we create an additional entry for 401.2 error by clicking on the Add… link under Actions on the right pane. You can duplicate the entry for 401 setup, except this time the Status code should have a value of 401.2. Click OK.

    IIS Site edit Custom Error Page for 401.2 error

  17. Now you should see the list in your Error Pages windows similar to this.

    List of error pages codes in IIS

That’s all there is to it.

As a test, we can try to load the page and when prompted to type in the a credential, you can leave it blank and click the Cancel button.

Microsoft Edge Windows Security screen

If you purposely fail the authentication to access your test website, you should see your custom 401 error page is displayed in your browser now.

IIS Render Custom 401 Error Page HTML

Yes, it’s almost like an anti-climax to see a plain custom 401 error page being displayed. I hope you can come up with a much better design than my example to make all the effort worthwhile.

If you go to your web folder, you will see a web.config file, and your configuration is saved there:

  <httpErrors allowAbsolutePathsWhenDelegated="true">
    <remove statusCode="401" subStatusCode="-1" />
    <error statusCode="401" prefixLanguageFilePath="c:\temp" path="ITNOTA-Custom-401.htm" responseMode="File" />
    <error statusCode="401" subStatusCode="2" prefixLanguageFilePath="c:\temp" path="ITNOTA-Custom-401.htm" responseMode="File" />
  </httpErrors>
</system.webServer>

IIS Custom 401 configuration in web.config

This setting for a custom 401 works for both ASP.NET and Classic ASP.

Further Reading

How to Customize 401 Error Page with 302 Redirect on IIS
How to Fix Access Denied (401) Error in Microsoft IIS
Custom 401 page in IIS with ASP.NET
Error: Vault Pre-check fails on TestASPNet.aspx – IIS shows absolute physical path is not allowed
500.19 error in IIS7 when an error occurs

June 28, 2021 Filed Under: How To Tagged With: IIS, Internet Information Services, Microsoft, Windows Server

How to Find Out When the Last Time Windows Server Was Rebooted

For various reasons such as patch application or software installation, a server needs to be rebooted. This simple step could potentially make or break the availability of your application. Just to have a quick information when your server was rebooted can help you in troubleshooting an issue.

There are several ways to find this information.

Using Command Prompt

A quick way to do this is by executing a systeminfo command from Command Prompt within your Windows Server.

  1. Launch Command Prompt and type in the following:

            systeminfo | find "Boot Time"
            

    There are some other variants you can see, but as far as obtaining the date and time of the server reboot, the final result is still the same.

            systeminfo | find /i "Boot Time"
            

    Command Prompt SystemInfo Boot Time

Using Task Manager

  1. In Task Manager, click on the Performance tab and look for the Up time. This will involve a bit of calculation to determine the exact date and time, but you can see how long the server has been running since its last reboot.

    Windows Server Task Manager Up time

Further Reading

systeminfo

April 14, 2021 Filed Under: How To Tagged With: Microsoft, Windows Server

How to Install Python on Windows Server

Python is an excellent general purpose language that can be used for batch processing and other tasks on your server.

To install Python on Windows Server operating system, you just need to run the installer and use the simplest configuration.

Steps to Install Python on Windows Server Operating System

  1. Download the installer (full as opposed to the web sintaller) and save it to your temp folder.

    Python installer in Windows Temp folder

  2. Right-click on the file and select Run as administrator.

    Run Python installer as administrator

  3. You’ll see a User Account Control popup window with a question, “Do you want to allow the following program to make changes to this computer?” Just click on Yes.

  4. Check the Add Python 3.7 to PATH checkbox at the bottom of the window (or whatever the latest version you’re installing).

    Install Python setup screen

  5. If you don’t care where the program is installed, you can just clik on the Install Now, there’s nothing wrong with the setup and Python will run and this is generally fine for desktop installation.

    For server installation, you should be more mindful with the program location better location rather than the default installation under a specific user folder who ran the installer. So it’s better to choose Customize installation.

  6. In Optional Features screen, make sure you at least check the following: pip, py launcher, and for all users. Click Next.

    Python customize installation optional features

  7. On the next screen, Advanced Options, make sure you check Install for all users which then will change the value of Customize install location, just accept the default installation in C:\Program Files unless you have a reason to install it somewhere else. Click Install.

    Python customize installation advanced options for all users

  8. Once you see Setup was successful just click the Close button.

  9. Make sure that C:\Program Files\Python37 and C:\Program Files\Python37\Scripts are in the Path of your System variables.

    Python added to path in Windows Environment Variables

    If you’re able to click on Edit button, you can see all the path entries in each line which is easier to read and edit. In this case, the button is greyed out due to the group policy.

As a final check, you can open Programs and Features and check if Python and Python Launcher are shown.

Programs and Features

That’s all there is to have your server running Python scripts.

If you work mostly with Microsoft stack and need to connect to a SQL Server database using Python, then check this post about Python SQL Server Driver.

Further Reading

How to Activate Built-in Web Server
How to Use Python to Connect to SQL Server

Download

Python Download

May 22, 2019 Filed Under: How To Tagged With: Microsoft, Python, Windows Server

« Previous Page
Next Page »
Buy me a coffee Support this site
Buy Me a Coffee?

Categories

  • .NET
  • Coding
  • Cybersecurity
  • Database
  • How To
  • Internet
  • Multimedia
  • Photography
  • Programming
  • Resources
  • Review
  • Tips and Tricks
  • Uncategorized
  • Use Case
  • WordPress
  • Writing

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Tags

.NET .NET Core AdSense ASP.NET Cdonts Dll Classic ASP Code Editor ETL FSharp Genesis Framework Git Google HP Asset Manager HTML5 Hugo IIS Information Security Internet Internet Information Services iOS JAMStack Linux macOS Microsoft Microsoft SQL Server MVC PHP PowerShell Python Simple Mail Transfer Protocol Smtp Server SQL SQL Server SSIS SSMS SSRS Sublime Text Visual Studio Visual Studio Code VPN Windows Windows 8 Windows 10 Windows 2012 Windows Server

Copyright © 2011-2025 IT Nota. All rights reserved. Terms of Use | Privacy Policy | Disclosure