PDA

View Full Version : Problems using Transfer mode



CheekyTinker
05-06-2005, 04:25 PM
Hi

I've started experimenting with the new Spring.Web stuff as I'm looking for an MVC solution for my .Net web apps.

It was all working superbly until I encountered the old "Error executing child request" when using the transfer mode of the Result mapping feature?

Redirect mode works fine, but I just can't get past this error with Transfer mode.

Any help much appreciated.

Aleks Seovic
05-07-2005, 07:27 AM
Hi,

Could you post a simplest example you can think of that gives you an error and I'll look into it.

Thanks,

Aleks

vivelafrique
05-11-2005, 02:13 AM
I've been having this same problem.

I created a new web project, with two Webforms, WebForm1.aspx and WebForm2.aspx.

WebForm1.aspx has a button that simply does
Server.Transfer("WebForm2.aspx");

My applicationContext.xml

<?xml version="1.0" encoding="utf-8" ?>
<objects>

<object id="WebForm1" type="WebForm1.aspx">
</object>
<object name="WebForm2" type="WebForm2.aspx"/>

</objects>


The top of my Web.Config

<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler,Spring.Core"/>
</sectionGroup>
</configSections>
<spring>
<context type="Spring.Context.Support.WebApplicationContext, Spring.Web">
<resource uri="applicationcontext.xml"/>
</context>
</spring>
And later

<httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
</httpHandlers>


Run Webform1.aspx, click the button, and get an error.

Let me know if you'd like my source. It's simple enough.

CheekyTinker
05-13-2005, 02:58 PM
Hi,

Sorry for the delay in replying, thanks for responding to my initial query.
The following code will fail with "error executing child..."

Here's my web config entry




<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>

<spring>
<context type="Spring.Context.Support.WebApplicationContext, Spring.Web">
<resource uri="config&#58;//spring/objects"/>
</context>
<objects xmlns="http&#58;//www.springframework.net">
<object type="Start.aspx" >
<property name="Results">
<dictionary>
<entry key="Register">
<value>transfer&#58;Test.htm</value>
</entry>
</dictionary>
</property>
</object>
</objects>
</spring>
<system.web>

...


<httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
</httpHandlers>



Start.aspx code is as follows:




using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Spring.Web.UI;
namespace HebNam.Web.SpringSampleWebApp
&#123;
/// <summary>
/// Summary description for Start.
/// </summary>
public class Start &#58; Spring.Web.UI.Page
&#123;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load&#40;object sender, System.EventArgs e&#41;
&#123;
// Put user code to initialize the page here
&#125;

#region Web Form Designer generated code
override protected void OnInit&#40;EventArgs e&#41;
&#123;
//
// CODEGEN&#58; This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent&#40;&#41;;
base.OnInit&#40;e&#41;;
&#125;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent&#40;&#41;
&#123;
this.Button1.Click += new System.EventHandler&#40;this.Button1_Click&#41;;
this.Load += new System.EventHandler&#40;this.Page_Load&#41;;

&#125;
#endregion

private void Button1_Click&#40;object sender, System.EventArgs e&#41;
&#123;
SetResult&#40;"Register"&#41;;
&#125;
&#125;
&#125;




The target page, Test.htm, is simply a plain Htm page to elminate that from the enquiry.


If I change the web.config entry from:



<value>transfer&#58;Test.htm</value>


to



<value>redirect&#58;Test.htm</value>


it works like a dream.


Thanks for your help

CheekyTinker
05-13-2005, 04:06 PM
Found this which may explain the problem...but then I am a little confused as to when you can use Server.Transfer

http://support.microsoft.com/default.aspx?scid=kb;EN-US;320439

Aleks Seovic
05-15-2005, 03:09 PM
Yeah, that might be a problem.

If you rename Test.htm to Test.aspx same ISAPI extension should be used and everything should work fine. Can you try and let me know if it still fails?

Thanks,

Aleks

vivelafrique
05-16-2005, 01:54 PM
In the example I posted above, I had the same error message trying to do a Transfer from one spring-controlled .aspx to another (no need to return to IIS, as mentioned in a previous post). As soon as I unmap the destination .aspx from Spring, the Transfer method works fine.

spmva
05-21-2005, 01:02 PM
i was having a similar problem with Server.Transfer. having written my own MVC framework under .net i know how frustrating Server.Transfer can be.

the problem, i believe, is related to recursive calls to the page handler.

i have a solution that seemed to work for the most simple solution of WebForm1.aspx navigating to WebForm2.aspx with Server.Transfer. i doubt it is a great solution, and with apologies to the spring guys, i had to hack up their code a bit to make it work. perhaps, the solution will be of some use in finding a final answer, especially if no one has any other ideas (not much activity on this post recently).

my solution works on the concept of aliasing the page you request and then using Server.Transfer to go to the actual page. it was the only way i could get my personal mvc framework to operate and it is how microsoft specifies the building of a front controller as part of their best practices.

to get this to work i made a few changes. there are probably more elegant ways to do the things i did and perhaps some are unnecessary, but i don't know the spring code base well enough to make those kind of design decisions.

the first change is in the web.config file:


<httpHandlers>
<add verb="*" path="Pg*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
</httpHandlers>

note the addition of the prefix "Pg" in the path attribute. to request a page you simply request the .aspx page prefixed with the "Pg" value. for example, a page called WebForm1.aspx would be requested by PgWebForm1.aspx.

the object definitions change slightly:


<object type="WebForm1.aspx" name="PgWebForm1" id="PgWebForm1">
<property name="Results">
<dictionary>
<entry key="go">
<value>transfer&#58;WebForm2.aspx</value>
</entry>
</dictionary>
</property>
</object>

<object type="WebForm2.aspx" name="PgWebForm2" id="PgWebForm2"></object>

spring did not require you to specify a name or id for the object (not really sure which one i needed here so i specified both to be sure). the name and id will be the name of the page prefixed with the "Pg" value. the idea here is to provide a mapping of the page request "PgWebForm1.aspx" to the physical "WebForm1.aspx". the rest of the object definition is the same as the spring examples.

to make all this work, i then just made some minor adjustments in the Spring.Web code to make it accept the "Pg" prefix for object lookups.

in Spring.Objects.Factory.Support.WebObjectDefinition Factory:


public override IConfigurableObjectDefinition CreateObjectDefinition&#40;string typeName, string parent, ConstructorArgumentValues arguments, MutablePropertyValues properties, AppDomain domain&#41;
&#123;
Type objectType = null;
bool isPage = StringUtils.HasText&#40;typeName&#41; && typeName.ToLower&#40;&#41;.EndsWith&#40;".aspx"&#41;;

if &#40;!isPage && StringUtils.HasText&#40;typeName&#41; && domain != null&#41;
&#123;
objectType = ObjectUtils.ResolveType&#40;typeName&#41;;
&#125;
if &#40;!StringUtils.HasText&#40;parent&#41;&#41;
&#123;
if &#40;objectType != null&#41;
&#123;
return new RootWebObjectDefinition&#40;objectType, arguments, properties&#41;;
&#125;
else if &#40;isPage&#41;
&#123;
// SPMVA&#58; change the name of the object
IConfigurableObjectDefinition def = new RootWebObjectDefinition&#40;typeName, properties&#41;;
def.FactoryObjectName = "Pg" + typeName;
return def;
&#125;
else
&#123;
return new RootWebObjectDefinition&#40;typeName, arguments, properties&#41;;
&#125;
&#125;
else
&#123;
if &#40;objectType != null&#41;
&#123;
return new ChildWebObjectDefinition&#40;parent, objectType, arguments, properties&#41;;
&#125;
else if &#40;isPage&#41;
&#123;
return new ChildWebObjectDefinition&#40;parent, typeName, properties&#41;;
&#125;
else
&#123;
return new ChildWebObjectDefinition&#40;parent, typeName, arguments, properties&#41;;
&#125;
&#125;
&#125;

in Spring.Web.Support.PageHandlerFactory:


public IHttpHandler GetHandler&#40;HttpContext context, string requestType, string url, string path&#41;
&#123;
IHttpHandler handler = &#40;IHttpHandler&#41; handlers&#91;url&#93;;
if &#40;handler != null&#41;
&#123;
return handler;
&#125;

InternalSecurityPermissions.UnmanagedCode.Assert&#40;&#41; ;

string pageName = WebUtils.GetPageName&#40;url&#41;;
IApplicationContext appContext;

try
&#123;
appContext = &#40;IApplicationContext&#41; context.GetConfig&#40;"spring/context"&#41;;
&#125;
catch &#40;ConfigurationException ex&#41;
&#123;
if &#40;ex.InnerException != null&#41;
&#123;
throw ex.InnerException;
&#125;
else
&#123;
throw ex;
&#125;
&#125;

if &#40;appContext.ContainsObjectDefinition&#40;pageName&#41;&#41;
&#123;
Type pageType = appContext.GetType&#40;pageName&#41;;

// SPMVA&#58; change the object name
string realName = pageName.Substring&#40;2, pageName.Length -2&#41;;

if &#40;typeof&#40;IRequiresSessionState&#41;.IsAssignableFrom&#40;pa geType&#41;&#41;
&#123;
handler = new SessionAwarePageHandler&#40;appContext, realName&#41;; //SPMVA&#58; pageName&#41;;
&#125;
else
&#123;
handler = new PageHandler&#40;appContext, realName&#41;; //SPMVA&#58; pageName&#41;;
&#125;
&#125;
else
&#123;
handler = PageParser.GetCompiledPageInstance&#40;url, path, context&#41;;
&#125;

if &#40;handler.IsReusable&#41;
&#123;
handlers&#91;url&#93; = handler;
&#125;

return handler;
&#125;

and also in that internal class PageHandler:


public void ProcessRequest&#40;HttpContext context&#41;
&#123;
// SPMVA&#58; change the object name
IHttpHandler page = &#40;IHttpHandler&#41; appContext.GetObject&#40;"Pg" + pageName&#41;;
page.ProcessRequest&#40;context&#41;;
&#125;

i think that was it. in any case i don't know what the down sides are to making things happen this way, but i do like that things work! <smiley_face>

CheekyTinker
05-22-2005, 09:07 AM
Thanks for replying... I saw someone had posted an example of transferring between two .aspx pages so didn't bother posting my own example...it was the same. A few people seem to be using Spring Web stuff in anger... I can't believe we are the only ones with this issue if it's as fundamental a problem as your workaround solution suggests. Attacking it from this direction, does anyone have a simple example where this works so I can figure out for myself what I'm doing wrong?

spmva
05-23-2005, 10:51 AM
well...my modification worked for about two seconds, until the navigation became a bit more complex. technically, my changes didn't really make things work any better than before. any light of brilliance that i perceived in myself has been dashed against the rocks. ack! i guess Response.Redirect will be my friend for a while longer.

Mark Pollack
05-23-2005, 03:23 PM
Hi,

I really appreciate you digging so deep into this - the web area is not my forte and Aleks will take a look as soon as he clears some stuff off his plate. Thanks again for the feedback.

Cheers,
Mark

roberto
08-04-2005, 04:35 AM
I'm having the same problems described earlier in this thread. Just wondering if I should keep trying to debug my issues.

BTW, thanks for having this .NET version!

Roberto

Aleks Seovic
08-13-2005, 07:08 PM
I believe this issue is now fixed. Problem was that Spring IHttpHandler wrappers (PageHandler and SessionAwarePageHandler) did not extend Page class but simply implemented IHttpHandler.

AFAIC this is really a Microsoft bug within HttpServerUtility.ExecuteInternal method, but fortunately I was able to fix the issue on our end by making our internal wrapper classes extend System.Web.UI.Page and by implementing IHttpHandler explicitly.

Give it a try and let me know if it works, code is just checked into the CVS.

- Aleks

stephenro
08-18-2005, 02:13 AM
Is this fix in Release 1.0RC1?

Thanks,

Steve

Aleks Seovic
08-18-2005, 06:32 AM
No, Spring.Web is not a part of 1.0 release (only Spring.Core and Spring.Aop are). You will have to get latest Spring.Web code from the CVS and build it yourself.

- Aleks

Rick Evans
08-18-2005, 07:29 AM
Hiya

Just a quick note to say that the Spring.Web library will be part of the next release. You can check out the roadmap here...

http://opensource.atlassian.com/confluence/spring/display/NET/Home

Ciao
Rick

Josephine
10-08-2007, 01:01 PM
Hi,

I'm trying out the full Spring.WEB solution for my web app, using the latest release, but I'm still having the server.Transfer problems described in the ealier posts. I was wondering if anyone had been able to get this working?

Thanks,

Josephine

Josephine
10-08-2007, 03:06 PM
Please ignore me! Just seen this...


Hi Sabrina,

did you try to disable "EnableViewstateMAC"? Does it work then?

cheers,
Erich

GuyMetz
10-26-2007, 01:16 PM
Server.Transfer() still seems to have issues in the latest release. The Page instance is not initialized in the same manner when the Spring aspx handler is in the stream. Particularly the PreviousPage property is not set. Looking at HttpServer.ExecuteInternal() it appears to be injecting values into the page instance which with the SpringHandler inserted would be the SessionAwarePageHandler stub not the requested page. The only fix that I see at the moment would be to have The stub handler forward the value for PreviousPage (unfortunately there is no public method for setting this variable).

Erich Eichinger
11-08-2007, 05:38 PM
Hi,

Thanks for reporting this. I entered a JIRA issue SPRNET-763 (http://opensource.atlassian.com/projects/spring/browse/SPRNET-763) and will look into it as soon as possible. Unfort. atm I cannot make any promises w.r.t schedule. If the fix doesn't make it into 1.1.0 it will sure make it into 1.1.1.
If you find a way to fix this problem, please let us know - of course this will shorten the time it takes to fix this ;-)

cheers,
Erich

Erich Eichinger
11-27-2007, 09:15 PM
Hi,

I'm currently looking into this issue.


Server.Transfer() still seems to have issues in the latest release. The Page instance is not initialized in the same manner when the Spring aspx handler is in the stream. Particularly the PreviousPage property is not set.

which overloaded form of Server.Transfer() do you use? Did you try

public void Transfer(string path, bool preserveForm) with preserveForm=true ?

I'd highly appreciate any hint on how to reproduce this problem.

thanks for your help,
Erich

Mark Pollack
02-10-2008, 10:50 PM
Hi,

Erich has made an integration test case (http://fisheye1.cenqua.com/browse/%7Eraw,r=1.1/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Web/Support/PageHandlerFactoryTests.cs) for this and has not been able to reproduce it so the issue has been closed. Test cases to reproduce the issue are much appreciated.

Cheers,
Mark