You are not logged in.
Hi,
Can't figure out how to send a custom content (json or text string) from a MVC Application (ex. 30 - MVC Server)
I have declared my custom function in MVCViewModel.pas:
IBlogApplication = interface(IMVCApplication)
['{73B27C06-9DB9-45A2-BEDD-2013CFB609D0}']
function Version: TServiceCustomAnswer;
...
function TBlogApplication.Version:TServiceCustomAnswer;
begin
Result.Header := TEXT_CONTENT_TYPE_HEADER;
Result.Content := FormatUTF8('Blog Version v1.0',[]);
Result.Status := HTML_SUCCESS;
end;
But when I call "blog/Version" it ask me to fill Version.html template.
Any help is welcome.
Thanks
Alexandre
Last edited by talexone (2016-08-11 16:28:44)
Offline
This is not how it works.
TServiceCustomAnswer is only for SOA interfaces, not for MVC interfaces.
Under MVC, it has another use, which is to perform redirection between pages.
You should use a method-based service instead, to send any custom content from the app.
Online
@ab: Thank you for your answer.
But if it's not to much to ask you to point it in mormot documentation or in samples.
Finally I have found a solution as you said with a method-based service:
type
TMyServer = class(TSQLRestServerDB)
published
procedure Version(Ctxt: TSQLRestServerURIContext);
end;
var aServer: TDeskScreen_Server;
...
procedure TMyServer.Version(Ctxt: TSQLRestServerURIContext);
begin
Ctxt.Returns(FormatUTF8('Blog Version v1.0',[]),HTTP_SUCCESS,TEXT_CONTENT_TYPE_HEADER);
end;
...
aServer := TMyServer.Create(aModel,ChangeFileExt(ExeVersion.ProgramFileName,'.db'));
Thank you again.
Last edited by talexone (2016-08-11 18:12:13)
Offline
In this case is there a way to know if a user is logged?
I'd like avoid that "Version" return the result if user is not logged in MVC application.
Is it possible? How?
Offline