13

Whenever I install a new font on a Windows 2003 server, I can't use it immediately in my asp.net web application. The application gets the font through the CreateFontIndirect gdi32.dll win api, and then use this font to create a dynamic text image in my asp.net application. It seems like fonts get cached somewhere, because I will just get the default font returned.

The font cache gets updated after a reboot, and then I get the correct font, but obviously I wouldn't like to do a reboot on a production server just for getting a new font to work.

Is there a way to flush the font cache?

Carvellis
  • 3,992
  • 2
  • 34
  • 66
  • How do you install the fonts? – Dean Harding Jun 03 '10 at 07:53
  • I install them by copying them into the windows\fonts folder. Windows shows the installing prgress bar and they appear correctly in the windows\fonts folder so it seems they are installed correctly. – Carvellis Jun 03 '10 at 07:54
  • btw they are regular TT fonts that normally work in the application, just not immediately after installing them in windows. – Carvellis Jun 03 '10 at 07:55

4 Answers4

15

By default, when you install a new font, only the current session is notified of the change. So if you're logging into the server in a terminal services session (which seems likely) then the ASP.NET application (which will be running in a different session) will not see the change.

When you reboot, the system automatically scans the font directory and "registers" all of the fonts in there into the current session.

To "manually" register a new font, you will need to call AddFontResource and pass in the path to the font.

To make it slightly easier, you could make it so that your app scans the Fonts folder and calls AddFontResource on each file it finds there in it's Application_Start event. That way, when you install a new font, you can just recycle the site (e.g. edit the web.config file) and it'll re-scan all of the files.

Another option would be to put a directory watch (via FileSystemWatcher) on the Fonts folder and automatically re-scan it.

I guess it just depends how often you'll be installing new fonts...

Dean Harding
  • 71,468
  • 13
  • 145
  • 180
  • 1
    So there is no possibility to rescan the fonts from outside the application for that particular session? – Carvellis Jun 03 '10 at 08:23
  • `AddFontResource` adds the font to the system for the *whole* session, so you could run another program in same session as ASP.NET to re-scan the directory and call `AddFontResource`, but whether there'd be much benefit I'm not so sure. – Dean Harding Jun 03 '10 at 08:31
  • 1
    [Well, Telerik certainly agrees with this post!](https://www.telerik.com/forums/install-new-font-and-need-to-restart-the-server#-HwkFar3hkes9GaVU77enQ) – Scott Jan 30 '18 at 18:18
  • This also applies to services. To get them to "see" a new font the machine has to be rebooted. Just restarting the service does not help. – PTBW Jun 28 '19 at 09:40
2

Restart IIS. that should do the trick. rub iisreset from command line or use IIS manager.

user1923248
  • 87
  • 1
  • 6
2

I recycle the application pool that use the fonts and it fixed.

  • Also make sure the font is installed for all users. The combination of app pool recycle and install for all users did the trick for me. – Rick Paul Nov 16 '22 at 23:34
1

When installing fonts on a server, NEVER double click them to install, otherwise it only installs for the current user. Instead you should right click the font file and select "Install for all users". The font will then be available right away for use in your web application.

Randall
  • 41
  • 3
  • This helped as I was missing 2 of the 10 fonts I installed. I had not used "Install for all users" That plus the Recycle Application Pool response above got the fonts to show up properly. – Rick Paul Nov 16 '22 at 23:33