Re: Modifying page output using Session data?

From: Al Cohen (amc79_at_no.junk.please.cornell.edu)
Date: 03/28/04


Date: Sat, 27 Mar 2004 21:48:49 -0500
To: Hugo Wetterberg <hugo@wetterberg.com>

Hugo:

One million thanks!

Not only is this short and sweet, but you already did all of the work
for me!

Best regards,

Al Cohen

Hugo Wetterberg wrote:

> One solution is to override the Render method and pass a html-writer
> based on a memory stream to the base.Render method. Then you only have
> to read the memory stream and replace whatever you want, no problems
> with accessing the session either.
>
> protected override void Render(HtmlTextWriter writer)
> {
> MemoryStream mem=new MemoryStream();
> StreamWriter w=new StreamWriter(mem);
> HtmlTextWriter htmlw=new HtmlTextWriter(w);
>
> base.Render (htmlw);
> htmlw.Flush();
>
> mem.Position=0;
> TextReader reader=new StreamReader(mem);
> string output=reader.ReadToEnd();
>
>
> writer.Write(output.Replace("${user}",(string)Session["username"]));
> }
>
> Cheers
> Hugo
>
> On Sat, 27 Mar 2004 11:20:02 -0500, Al Cohen
> <amc79@no.junk.please.cornell.edu> wrote:
>
>
>>I'm attempting to build a templating engine that will substitute the
>>values of session variables for tags in a page before the page gets sent
>>to the client. For example, the contents of Session["UserName"] would
>>replace each instance of ${UserName} in the page just before the page is
>>returned.
>>
>>In principle, this should be easy to do by hooking into one of the
>>HttpApplication events that occurs after the request handler runs, but
>>I'm having trouble figuring out exactly how. The problem is that to do
>>this, I need to satisfy two conditions:
>>1. I must have access to the Session
>>2. I must be able to manipulate (i.e., random search, delete, and write)
>>the page contents.
>>
>>It looks like I can only manipulate the page contents in a filter
>>attached to HttpResponse.Response; otherwise, I can only append to the
>>Response. (Is this true?)
>>
>>If I can only manipulate the page in a filter, that would be OK, as long
>>as the filter has access to the Session. However, a little
>>experimenting indicates that the Session is gone after
>>PostRequestHandlerExecute occurs, which is before the response filters
>>are executed.
>>
>>So, I seem to be unable to manipulate the entire page and read a session
>>at the same time.
>>
>>Any suggestions would be VERY appreciated!
>>
>>Thanks,
>>
>>Al Cohen
>>www.alcohen.com
>
>



Relevant Pages

  • Re: Modifying page output using Session data?
    ... based on a memory stream to the base.Render method. ... with accessing the session either. ... I must be able to manipulate ... >If I can only manipulate the page in a filter, that would be OK, as long ...
    (microsoft.public.dotnet.framework.aspnet)
  • Modifying page output using Session data?
    ... I must have access to the Session ... I must be able to manipulate ... If I can only manipulate the page in a filter, that would be OK, as long ... which is before the response filters ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to log telnet session?
    ... > I would like to run a telnet session, ... I want to manipulate the contents of the ... When you have taken care of basics like using a real newsreader, ... Google is for reading the Archives. ...
    (comp.unix.shell)
  • Re: How to log telnet session?
    ... > I would like to run a telnet session, ... I want to manipulate the contents of the session log ... > copy/paste lines into files to then be manipulated by shell scripts. ... If so xterm can log all output to a file. ...
    (comp.unix.shell)
  • Re: Problem with Filters in web application
    ... But if the unsecured page would manipulate the ... session the filter would not pass since the object is not in the ... Prev by Date: ...
    (comp.lang.java.programmer)