Jon, inline...

> The reason that adding the Reference directives fixes the problem, is
> because internally inside of the call to GetCompiledPageInstance - the
> ASP.NET runtime is parsing each file seperately and compiling them (i.e.
not
> calling GetCompiledPageInstance again). GetCompiledPageInstance is only
> intended to be called from the HandlerFactory (I am assuming this since it
> obviously is ill-prepared to be called more than once).  Once compiled, an
> item (ParserCacheItem) is added to the HttpRuntime's Cache.  What happens
> when you call GetCompliedPageInstance more than once (although I could not
> find exactly where/why in the call stack this happens) is that the second
> page name (in this case Test2.aspx) is associated with the Type that was
> compiled from Test1.aspx.

This is what's bugging me.  Each call to GetCompiledPageInstance creates a
new PageParser instance.  It creates a key, eg:

"System.Web.HttpConfig:" + Request.BaseDir + pageName

and searches the cache with that key.  If it finds a matching
ParserCacheItem, gets its Type, and asks HttpRuntime to
CreateNonPublicInstance of that type.  If it doesn't find a match, it kicks
off the whole compilation process which I can't face trawling through <g>.

So, when I first hit RunMe.aspx, neither Test1.aspx nor Test2.aspx is in the
cache.  On the first call to GetCompiledPageInstance, Test1.aspx gets
compiled, added to the cache with its key, and instanciated.  But on the
second call to GetCompiledPageInstance, a *new* parser, given a *new* key to
look for in the cache, is still coming up with Test1.aspx.

> Another way to make this work correctly is to hit Test1.aspx and
Test2.aspx
> with a browser before hitting RunMe.aspx, which associates the correct
Type
> with the correct page name in the Cache.

True, and given that the HttpApplication will map those two URLs to the
correct handlers (and which is achieved by calling GetCompiledInstanceOfPage
in much the same way), I can't see where I'm going wrong.

> In any event, I don't believe GetCompiledPageInstance was intended to be
> called in this manner.  Using the Reference directive is the standard way
of
> including another .aspx file.

This isn't an option unfortunately.  I need to create page (or any other
handler) instances on the fly, without having the type information to hand.

Thanks for your response,

Jim

> -----Original Message-----
> From: Moderated discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED] Behalf Of Jim Arnold
> Sent: Thursday, February 27, 2003 10:17 AM
> To: [EMAIL PROTECTED]
> Subject: [ADVANCED-DOTNET] Problem with ASP.Net's parser
>
>
> Could someone sanity check this for me?  Create two pages, Test1.aspx and
> Test2.aspx, like so:
>
> -----------------------------------------------------
> <%@ Page ClassName="Test1"%>
>
> hello from test1
> -----------------------------------------------------
> <%@ Page ClassName="Test2"%>
>
> hello from test2
> -----------------------------------------------------
>
> And a third called RunMe.aspx:
>
> -----------------------------------------------------
> <script runat="server" language="C#">
>  void Page_Load(object o, EventArgs e) {
>   IHttpHandler test1 =
> PageParser.GetCompiledPageInstance(Request.ApplicationPath,
> Server.MapPath("Test1.aspx"), Context);
>   test1.ProcessRequest(Context);
>   IHttpHandler test2 =
> PageParser.GetCompiledPageInstance(Request.ApplicationPath,
> Server.MapPath("Test2.aspx"), Context);
>   test2.ProcessRequest(Context);
>  }
> </script>
> -----------------------------------------------------
>
> Put them all in a browseable ASP.Net folder and hit RunMe.aspx.  You
should
> see this output:
>
> hello from test1 hello from test1
>
> Tests on both instances confirm that they are of type ASP.Test1, instead
of
> ASP.Test1 and ASP.Test2 as I would expect.  Now, add the following
> directives to RunMe.aspx:
>
> <%@ Reference Page="Test1.aspx" %>
> <%@ Reference Page="Test2.aspx" %>
>
> Now touch (edit and save) Test1.aspx and Test2.aspx to recompile them, and
> hit RunMe.aspx again.  You should see:
>
> hello from test1 hello from test2
>
> So my questions are: why is PageParser returning instances of the same
type
> for two different file paths, and why does adding references to the pages
> fix this?
>
> Incidentally, if you take out the ClassName directives from Test1.aspx and
> Test2.aspx, and remove the Reference directives from RunMe.aspx,
PageParser
> works as expected.
>
> I am running 1.0.3705 on Windows XP Home, through Cassini.
>
> Thanks for your time,
>
> Jim
>

Reply via email to