delphimvcframework
delphimvcframework copied to clipboard
Routing is broken when Config[TMVCConfigKey.PathPrefix] is set
If you set a Prefix like
Config[TMVCConfigKey.PathPrefix] := '/v1/pjapi.dll';
then the function TMVCRouter.ExecuteRouting fails to find the correct route and ends always in a "404 Not Found" error.
i had to change following code lines in MVCFramework.Router to get it work:
replaced the line
if not LRequestPathInfo.StartsWith(APathPrefix + LControllerMappedPath, True) then
with
if not LRequestPathInfo.StartsWith(LControllerMappedPath, True) then
and
if IsCompatiblePath(APathPrefix + LControllerMappedPath + LMethodPath, LRequestPathInfo, ARequestParams) then
with
if IsCompatiblePath(LControllerMappedPath + LMethodPath, LRequestPathInfo, ARequestParams) then"
I am not sure if i did it the right way, but it works now in isapi with prefix and local as exe without prefix. Maybe this is worth to get a deeper look on it?
Why do you need that ugly path for ISAPI? My URLs look like
https://service.health.co.nz/v1/resource/2
I posted a guide here back in 2019 which explains how to host isapi files on IIS https://github.com/danieleteti/delphimvcframework/issues/217
- I readed your guide some months ago, tried to implement step by step, but i was out of success. Maybe with a fresh installed IIS i would work, but in my case it did not.
- We have nearly 40 services running, many of them depends on each other by URL, all designed with the dll name in the URL. It is not easy to change this.
- If i can set a PathPrefix, it should work in any case.
No probs, I understand that sometimes legacy deployment can rule out cleaner solutions 😀
I am not sure if i did it the right way, but it works now in isapi with prefix and local as exe without prefix. Maybe this is worth to get a deeper look on it?
PathPrefix must be used only with ISAPI dll (at least if you don't want to prepend some prefix on all your routes dinamically).
Please, try to use IFDEF and define PathPrefix for the isapi only for the ISAPI build.
Something like the following:
{$IF Not Defined(CONSOLE)}
Config[TMVCConfigKey.PathPrefix] := '/v1/pjapi.dll';
{$ELSE}
Config[TMVCConfigKey.PathPrefix] := ''; // just to be clear
{$ENDIF}
I am not sure if i did it the right way, but it works now in isapi with prefix and local as exe without prefix. Maybe this is worth to get a deeper look on it?
PathPrefixmust be used only with ISAPI dll (at least if you don't want to prepend some prefix on all your routes dinamically). Please, try to useIFDEFand define PathPrefix for the isapi only for the ISAPI build.Something like the following:
{$IF Not Defined(CONSOLE)} Config[TMVCConfigKey.PathPrefix] := '/v1/pjapi.dll'; {$ELSE} Config[TMVCConfigKey.PathPrefix] := ''; // just to be clear {$ENDIF}
That is exactly how i do it. The problem is that with ISAPI and the PathPrefix '/v1/pjapi.dll' it does not work. I would say it wont work with any PathPrefix you set other than '', when you do not make the changes i mentioned above. That is my point.