![]() |
class function TIWExceptionRendererEx.RenderHTML - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html) +--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html) +---- Forum: English (https://www.atozed.com/forums/forum-16.html) +----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html) +----- Thread: class function TIWExceptionRendererEx.RenderHTML (/thread-3107.html) |
class function TIWExceptionRendererEx.RenderHTML - Mikael Nilsson - 03-31-2023 Hi, I'm using this function with great success. But I need to reference a variable in the UserSession. How do I do that? RE: class function TIWExceptionRendererEx.RenderHTML - Alexandre Machado - 04-07-2023 I suppose that within your code you have access to your WebApplication instance, is that correct? The property Data of the WebApplication contains a reference to your UserSession object: UserSession := TIWUserSession(WebApplication.Data); However, the typecast will require you to link the unit with this code to the UserSessionUnit where TIWUserSession is declared. Another alternative is to use the UserSessionBase (the parent class of your UserSession) Clipboard object to temporarily store some values that are needed elsewhere. Something like: uses IWUserSessionBase; UserSession := TIWUserSessionBase(WebApplication.Data); // Store the value there UserSession.Put("LoggedUser", "Mikael Nilsson"); // Store the value there UserName := UserSession.Get("LoggedUser"); Note that in this example I don't need to link with the UserSessionUnit, only with the IWUserSessionBase unit which is part of the IW not your application. You can have a more generic approach using this. RE: class function TIWExceptionRendererEx.RenderHTML - Mikael Nilsson - 04-07-2023 (04-07-2023, 12:17 AM)Alexandre Machado Wrote: I suppose that within your code you have access to your WebApplication instance, is that correct? Hi, Sorry I don't understand the code. It's hard for me to understand what procedure/function you have assigned that code. What I understand TIWExceptionRendererEx.RenderHTML(AException: Exception; ARequest: THttpRequest): string; executes first and then TIWServerController.IWServerControllerBaseCloseSession(aSession: TIWApplication); I want to send a value from TIWExceptionRendererEx.RenderHTML to a variable in the userssion. and then IWServerControllerBaseCloseSession use that variable so i can update my table with the exception class. -------------------------------------------------------------------------------------------------------------------------------------------------- RE: class function TIWExceptionRendererEx.RenderHTML - Alexandre Machado - 04-07-2023 So use the first line that I wrote in my response: UserSession := TIWUserSession(WebApplication.Data); Now you have your UserSession and is able to call it's methods RE: class function TIWExceptionRendererEx.RenderHTML - Mikael Nilsson - 04-07-2023 (04-07-2023, 09:36 AM)Alexandre Machado Wrote: So use the first line that I wrote in my response: If I put that row first in TIWExceptionRendererEx.RenderHTML I get a compile error: Lefts side cannot be assign to RE: class function TIWExceptionRendererEx.RenderHTML - Alexandre Machado - 04-07-2023 You need to declare a variable of type TIWUserSession to assign the value to. In the example above I used UserSession but probably the compiler is trying to use the UserSession function. Use a different name instead: as I mentioned before, I'm assuming you have access to the WebApplication. If not, use gGetWebApplicationThreadVar() instead. The complete code should be: Code: uses RE: class function TIWExceptionRendererEx.RenderHTML - Mikael Nilsson - 04-07-2023 (04-07-2023, 08:50 PM)Alexandre Machado Wrote: You need to declare a variable of type TIWUserSession to assign the value to. Hi, Unfortunately it seems that the TIWApplication instance don't exists when an exception is raised. So I guess that is it. Or is it another solution? I hope you understand I'm doing this code in the ServerController? RE: class function TIWExceptionRendererEx.RenderHTML - Alexandre Machado - 04-07-2023 The exception handler executes in case any exception is raised, including the ones that occur outside the scope of a session. In this case, no IWApplication instance will exist. In some other cases it will... That's why our TIWExceptionLogger was designed to save a plain text file on the hard disk, because the disk is always available. RE: class function TIWExceptionRendererEx.RenderHTML - Mikael Nilsson - 04-08-2023 (04-07-2023, 10:35 PM)Alexandre Machado Wrote: The exception handler executes in case any exception is raised, including the ones that occur outside the scope of a session. In this case, no IWApplication instance will exist. In some other cases it will... Hi, So is it possible to read that log file from IWServerControllerBaseCloseSession? |