Skip to content

Mustache path issue for ISAPI modules (and fix) #827

@fastbike

Description

@fastbike

Changes since Sodium to increase the efficiency of loading Mustache templates has broken ISAPI implementations with a path error for locating templates.

The cause is in the LoadPartials method, where the following line uses the directory that the IIS Worker Process (c:\windows\system32\inetsrv\w3wp.exe) as the root for resolving relative paths rather than the directory where the ISAPI dll is located.

procedure TMVCMustacheViewEngine.LoadPartials;
<snip>
        lPartialFileNames := TDirectory.GetFiles(lViewPath, '*.' + lViewsExtension, TSearchOption.soAllDirectories);

As the directory does not exist under the w3wp directory, the Delphi runtime will return an error
'The specified path was not found [c:\windows\system32\inetsrv\templates]'.

Previous functionality in Sodium and earlier did not try to get a list of all mustache partials and only resolved this at view time with a call to GetRealFileName. This internally makes a call (through several layers of code) to GetModuleName which will return the full path and name of either a native EXE or the DLL that the code is running in.

The proposed fix is to change the code in LoadPartials

procedure TMVCMustacheViewEngine.LoadPartials;
<snip>
      if not gPartialsLoaded then
      begin
        lViewsExtension := Config[TMVCConfigKey.DefaultViewFileExtension];
        lViewPath := TMVCBase.GetApplicationFileNamePath + Config.Value[TMVCConfigKey.ViewPath];
<snip>

This requires that the class function TMVCBase.GetApplicationFileNamePath is made public.

Metadata

Metadata

Labels

acceptedIssue has been accepted and inserted in a future milestonehelp wanted

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions