IT Nota

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

How to Cache Specific Static Files and Directories on IIS

As part of IIS performance tuning to improve a web page load speed, in general you want to enable browser caching by double-clicking on HTTP Response Headers in IIS Manager, click on Set Common Headers and check the Expire Web content:, then set the After: with an x number of days.

IIS HTTP Response  Headers to Cache Static Files

Often times though, you may want to be more granular in IIS static content caching for different type of files or all static files under certain folders. In the same way that you can disable browser caching for specific files on IIS, you can also configure the web.config to setup browser caching for specific files or directories with different lengths of time.

<configuration>
...
  <location path="favicon.ico">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
      </staticContent>
    </system.webServer>
  </location>
  <location path="js">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="60.00:00:00" />
      </staticContent>
    </system.webServer>
  </location>
  <location path="images">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
      </staticContent>
    </system.webServer>
  </location>
</configuration>

In this example we can see the caching for a specific file favicon.ico is set to 1 year (365 days) and two folders js and images are set to 60 and 30 days respectively (In a format of days.hours:minutes:seconds). This means, all static files under js folder will be cached for 60 days, similarly for images folder, although for less duration since the contents change more frequently.

By caching as many static files as possible on the browser, you can tremendously improve IIS performance, which translates to better users experience in loading your site faster on their subsequent visits.

Further Reading

Disable Browser Caching for Specific Files on IIS

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

How to Make Visual Studio Code Colorize Classic ASP Code

If you still have to do development with Classic ASP or VBScript and you want to use Visual Studio Code, you’ll soon find out that even though the code editor was built by Microsoft, there’s no language colorization support for ASP code by default. Fortunately, adding the feature can be done easily using Extensions. So here are the steps to do so:

  1. Launch Visual Studio Code and click on Go and select Go to File… or just press CTRL-P.

    Visual Studio Code Goto File

  2. On the dialog box, type in the following: ext install classic asp and press [ENTER].

    Another way to do it, you can just click on the Extensions icon (it should be the last one on the left-hand side (or press CTRL+SHIFT+X) and type in classic asp in the search box.

    Visual Studio Code Ext Install Classic ASP

  3. Select Classic ASP by Ilya Verbitskiy and click on the Install button as shown below:

    Visual Studio Code Extensions Marketplace for Classic ASP

  4. Once installed, we still have to associate the asp file extension to the newly ASP colorizer so we don’t have to manually select ASP as the language every time we open an ASP file. As it is now, Visual Studio Code still has no way to detect it as an ASP page so it will treat it as an HTML file.

    From the File menu, open Preferences and select Settings (CTRL + ,).

    Visual Studio Code Preferences Settings

  5. In Search settings box, type in “file associations” and you can either click on the Add Item button and populate the Item and Value (option 1), or you can click on link Edit in settings.json (option 2). In the older version of Visual Studio Code, only option 2 was available, but now if you only have a few entries, option 1 would be easier to do.

    Visual Studio Code Settings File Associations

  6. If you chose option 1, after adding the items, if you clicked on Edit in settings.json you should see the following:

    "files.associations": {
      "*.asp": "asp",
      "*.vbs": "asp",  // optional
      "*.inc": "asp"   // optional
    }
    

    Visual Studio Code file associations User Settings

    If you chose option 2 though, you have to add those in yourself.

  7. Save the file (CTRL-S) and close it.

That’s all there is to it, now you every time you open an asp file (or vbs script for that matter), the selected Language Mode will be set to ASP and any classic ASP code will be colorized accordingly.

This is not limited to ASP only, you can always look for any language of your choice by going to Visual Studio Marketplace.

Further Reading

Adding Language Colorization
How to Reassign Shortcut Key for Column Selection in Visual Studio Code

Download

Visual Studio Code
Classic ASP (Classic ASP Language Support) – Ilya Verbitskiy

June 3, 2016 Filed Under: How To Tagged With: Classic ASP, Code Editor, Microsoft, Visual Studio Code

How to Fix Could Not Create a Disk Cache Sub-Directory for the Application Pool on IIS

During one of the upgrade projects from Windows Server 2003 to Windows Server 2008 32-bit, the following error occurs:

Source : Active Server Pages

Error: The Template Persistent Cache initialization failed for Application Pool 'AppPoolName' because of the following error: Could not create a Disk Cache Sub-directory for the Application Pool. The data may have additional error codes..

This happened soon after the Windows Server 2003 was in-place upgraded to Windows Server 2008.

One the problems here is after the upgrade, the default ASP Compiled Templates folder got moved but the application config is still pointing to the old path. The second issue is typically the new folder does not have permissions setup properly.

As a background information, the Application Pool for this classic ASP application is run under .NET Framework v2.0 with Managed Pipeline Mode Classic and Identity set to NetworkService.

So here are the steps to fix the issue.

Give Permissions to ASP Compiled Templates Folder

  1. Open Windows Explorer and go to %SystemDrive%\inetpub\temp and you should see a folder called ASP Compiled Templates.

  2. Right-click on the folder and select Properties and click on the Security tab.

    ASP Compiled Templates folder Properties

  3. If this is the first time you access it, you may see the prompt as shown below. Just click the Continue button and you’ll see the Advanced Security Settings for ASP Compiled Templates screen.

    ASP Compiled Templates Security Tab

  4. On the Change owner to: box, select either your group or your NTID and check Replace owner on subcontainers and objects and click OK and Yes when prompted by Windows Security box (All permissions will be replaced if you press Yes).
  5. As instructed, you should close all dialog boxes and go back to the folder’s Properties and click on the Security tab again. This time, you should be able to add a user.
  6. Click on the Add… button and type in Network Service and click OK.
  7. Highlight NETWORK SERVICE and check Full control on the Permissions for NETWORK SERVICE box.

    Set full permission for NETWORK SERVICE for ASP Compiled Templates

  8. Click OK two times to close all dialog boxes

Now we have set the permission, we also need to modify the value of the new path in applicationHost.config file.

Fix Application Config File

  1. Open Windows Explorer and go to %Windir%\System32\inetsrv\config and look for a file applicationHost.config.
  2. Backup applicationHost.config file.
  3. Open applicationHost.config either using a Notepad or any text editor.
  4. Search for “ASP Compiled Templates” and you should find the diskTEmplateCacheDirectory value for the old path.

    Modify path for ASP Compiled Templates in applicationHost.config file

  5. Change the old path to the new one. In this example, the new path is %SystemDrive%\inetpub\temp\ASP Compiled Templates.

    <cache diskTemplateCacheDirectory="%SystemDrive%\inetpub\temp\ASP Compiled Templates" maxDiskTemplateCacheFiles="2000" scriptFileCacheSize="250" scriptEngineCacheMax="125" enableTypelibCache="true" />
    
  6. Save the change and close Notepad.

Along with this error, another error HostableWebCore (Event ID 5053) also occurred, but that was easily fixed by following the steps from this Microsoft Technet article.

Further Reading

Template Persistent Cache Error with Classic ASP under IIS 7
“The Template Persistent Cache initialization failed for Application Pool” on IIS 7 using Classic ASP Issue
Can I delete “C:\inetpub\temp\ASP Compiled Templates” folder?
Event ID 5053 — IIS WAS Configuration

July 23, 2015 Filed Under: How To Tagged With: Classic ASP, IIS, Internet Information Services, Microsoft, Windows Server

How to Manage IIS Servers Remotely with WMSVC

One of the better ways of managing IIS is by doing it remotely from your local computer instead of logging in to the server itself. The Web Management Service (WMSVC) in IIS allows a remote connection into a Windows Server 2012 R2 by using the IIS Manager GUI. This is a much lighter connection compared to do an RDP connection to the server.

Here are the steps we need to do before we can use our local IIS Manager to control other remote IIS servers:

Install Management Service Role

  1. Launch IIS Manager and click on Add roles and features.

    Server Manager Dashboard on Windows Server 2012 R2

  2. Click Next > three times until you’re on the section called Server Roles on the left pane.
  3. Go to the right pane called Roles and expand on Web Server (IIS) and Management Tools and check the Management Service.

    IIS Server Roles Management Service (WMSVC)

  4. Click Next > two times until you see the confirmation screen and click on the Install button. You can click on the Close button even before it’s finished the installation. The only downside if you close it early is that there’s no explicit way for you to see if the installation is already completed.

    IIS Add Roles Confirmation Screen

Configure IIS Remote Connection

  1. Still on the server side, launch IIS Manager to configure the Management Service. On the center pane, you should see an icon called Management Service now under the Management area. Double-click on the icon to launch it.

    IIS Management Service icon

  2. On the Management Service window you can do all other configurations here, but at the very least you need to check the Enable remote connections and click on Apply to save it. Afterwards, click on Start hyperlink to activate it.

    IIS Management Service Enabled

    For increased security you might want to restrict certain IP addresses allowed to connect remotely by configuring the IP Address Restrictions on the Management Service. But basically, this is all you need to enable the IIS server for a remote management.

Configure Remote IIS Manager

Now we’re done with the server side, we just need to configure the remote desktop (or your local PC) that we want to use to manage the IIS from.

  1. Launch IIS Manager on the remote computer by opening Control Panel, then click on System and Security, Administrative Tools.
  2. On the Connections, you can either do a right-click on the Start Page or on the connection icon and select Connect to a Server.

    If you don’t see the Connect to a Server option, then you have to install IIS Remote Administration on your local PC first.

    IIS Manager connect to a server

  3. Enter the Server name and click Next.
  4. Type in your NTID credentials and click Next. After a successful confirmation, just click Finish.

That’s all the minimum configurations you need to do to manage IIS servers remotely via Web Management Service (WMSVC).

Further Reading

How to Manage IIS Servers Remotely
How to Install IIS Management Console on Windows
How to Backup IIS Manager Connections List on Windows
Mastering Windows Server 2019: The complete guide for system administrators to install, manage, and deploy new capabilities with Windows Server 2019, 3rd Edition
Open IIS Manager (IIS 7)

May 27, 2015 Filed Under: How To Tagged With: IIS, Internet Information Services, Microsoft, Windows Server

How to Fix Obsolete ConfigurationSettings.GetConfig API

When you’re upgrading code from .NET Framework 1.1 to 2.0, you will get a few warnings if you use an obsolete API such as ConfigurationSettings.GetConfig, you may see something similar to this:

This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.GetSection

To which you have to replace it with ConfigurationManager.GetSection(). Or the same way with ConfigurationSettings.AppSettings.Get() to ConfigurationManager.AppSettings.Get(). The problem is after you made the change, you will encounter another error during compilation such as this:

'ConfigurationManager' is not a member of 'Configuration'.

The solution, while it’s not intuitive is actually very simple. You need to add a reference to System.Configuration.dll to the assembly.

  1. If you’re using a default view, on the right pane of your Visual Studio under your project you can right click on the References and select Add Reference….

    Add reference in Visual Studio's solution explorer

  2. Under Assemblies, look for System.Configuration and make sure it’s checked, then click OK.

    Add System.Configuration.dll reference in Visual Studio

That’s all there is to it.

Further Reading

ConfigurationSettings.GetConfig Method

April 27, 2015 Filed Under: .NET Tagged With: ASP.NET, Microsoft, Visual Studio

« 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