Bug in _Post() methods

16 views
Skip to first unread message

Marco v. Frieling

unread,
Feb 13, 2007, 9:32:04 AM2/13/07
to PageMethods
Hello.

I have a user control inside a DataList, containing a hyperlink
control, which I'll set to a POST url. I'm doing this in the way

DeleteLink.NavigateUrl =
MyPageMethods.ImageList.DeleteImage_Post(item.ID, Page);

But what really happens for 20 items behaves like this:

for (int i = 0; i <= 20; i++){
string url = MyPageMethods.ImageList.DeleteImage_Post(i, Page);
// url ==
"PageMethods_ProcessPost_d8ce7733ef994b3fb1d41ddf8c90e90f()"
// independent of the current value of i.
}

That means, which delete button in my page I'll click on, always the
first item will be deleted. What's going on here?

Thanks.

Marco

Fabrice Marguerie

unread,
Feb 13, 2007, 10:50:03 AM2/13/07
to PageMethods
Hello Marco,

You've just found a bug!
I've identified it and I'll provide a fix for it within a week. I'm
currently preparing a new release.
In the meantime, a quick workaround you can use it to edit the
PageList.xml.cs by hand and do the following:
- locate the DeleteImage_Post method in PageList.xml.cs
- add the following line near the beginning of the method: string tmp
= "_"+System.Guid.NewGuid().ToString("N");
- change the declaration of clientFunction by appending tmp at the
end, like this (the GUID will be different): string clientFunction =
"PageMethods_ProcessPost_d8ce7733ef994b3fb1d41ddf8c90e90f"+tmp;
- likewise, append tmp at the end of the key parameter in the call to
pm_Control.Page.ClientScript.RegisterClientScriptBlock. e.g.:
pm_Control.Page.ClientScript.RegisterClientScriptBlock(pm_Control.Page.GetType(),
"ProcessPost_d8ce7733ef994b3fb1d41ddf8c90e90f"+tmp...

This is far from being perfect of course because you'll have to do
this each time the PageList.xml.cs is generated, which happens
often...

I'll do my best to publish a version with a fix soon.

Fabrice

Marco v. Frieling

unread,
Feb 14, 2007, 2:15:20 PM2/14/07
to PageMethods
Hello Fabrice,

> You've just found a bug!
> I've identified it and I'll provide a fix for it within a week. I'm
> currently preparing a new release.

Ok, thanks. At the moment I've changed it to use normal Buttons and
normal Postbacks.

BTW (I thouhgt I've posted it some weeks ago, but cannot find it), it
looks very strange if the URL in the browser changes on posting back
the same page. This happens because the _Post() methods request the
physical Url (TildePageUrl) instead the rewritten Url. Maybe you can
change that in the same realese!?

Thanks.

Marco

Fabrice Marguerie

unread,
Feb 14, 2007, 4:32:26 PM2/14/07
to PageMethods

> BTW (I thouhgt I've posted it some weeks ago, but cannot find it), it
> looks very strange if the URL in the browser changes on posting back
> the same page. This happens because the _Post() methods request the
> physical Url (TildePageUrl) instead the rewritten Url. Maybe you can
> change that in the same realese!?

I haven't seen a post about this lately.
This is a common problem with ASP.NET. I think you can find a solution
here: http://weblogs.asp.net/jezell/archive/2004/03/15/90045.aspx
Probably I should document this, or even include the solution in
PageMethods' BasePage class.

Fabrice

Marco v. Frieling

unread,
Feb 15, 2007, 5:23:51 AM2/15/07
to PageMethods
> This is a common problem with ASP.NET. I think you can find a solution
> here:http://weblogs.asp.net/jezell/archive/2004/03/15/90045.aspx

Ok, I'm understanding.

> Probably I should document this, or even include the solution in
> PageMethods' BasePage class.

It would be very helpful if you document this, but better if you
provide a solution. I don't know if the BasePage class is the right
place. E. g. I have some pages not using PageMethods for different
reasons in my project, but lots doing so. And I have a own BasePage
all my pages inherit from. But because of the some pages without
PageMethods my BasePage class does not inherit from PageMethods
BasePage class and instead implements the logic to run
PageMethodsEngine in the Page_Load method depending on an abstract
property

protected abstract bool UsePageMethods {get;}

I found another bug in PageMethods, not directly in your code, but in
the FAQ code for enabling PageMethods with HTTP POST. It doesn't work
in combination with www.urlrewriting.net because implementing the code
fragmeent in the Global.asax as shown in the PageMethods FAQ it will
be executed after the Url was rewritten by the urlrewriting module and
therefore not work. The solution for that problem is to put that code
in an HttpModule class and register that module in the web.config
before the urlrewriting module.

But the bug is that Script enabled Web Services in ASP.NET AJAX 1.0
break if you add the PageMethods POST data to the reqeust to an Web
Service method (*.asmx). So I changed the code to only add the POST
data to requests which actually can be processed by PageMethods. Maybe
you inlcude this module in PageMethods assembly and update the FAQ. So
you could add the code exchanging the HtmlTextWriter instance for
rendering also in that module.

Kind Regards

Marco


===== PageMethodsModule.cs =====
using System;
using System.Web;
using System.Web.UI;

namespace MetaSapiens.PageMethods
{
public class PageMethodsModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}

private static void context_BeginRequest(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;

if (context != null && context.Request != null &&
IsSupportedHandler(context.Handler))
{
// Handle HTTP POST
string newUrl =
PageMethodsEngine.AddPostData(context.Request.RawUrl,
context.Request);

// Update the path
context.RewritePath(newUrl, false);
}
}

/// <summary>
/// Add POST data only for <see cref="IHttpHandler">handlers</see>
supported by PageMethods.
/// </summary>
/// <param name="handler"><see cref="IHttpHandler"/></param>
/// <returns><c>true</c> if the current handler is supported by
PageMethods, <c>false</c>
/// otherwise.</returns>
private static bool IsSupportedHandler(IHttpHandler handler)
{
if (handler == null) return false;
if (handler is Page) return true;

// Only Pages are supported at the moment. If other Handlers are
supported too,
// they should be added here, maybe *.ashx. Maybe a PageMethods
BaseHandler class would be needed implementing
// the call to PageMethodsEngine. Maybe this method must be changed
to check extension for *.aspx (, *.ashx and other
// configurable extensions which are mapped to a custom handler
supporting PageMethods).

return false;
}

public void Dispose()
{
}
}
}

Fabrice Marguerie

unread,
Apr 3, 2007, 9:29:41 AM4/3/07
to PageMethods
Hello Marco,

I have just released a new version of PageMethods (1.7.2) that
addresses the problems you report here.
I have been able to reproduce the issue with multiple POST links on
one page. Could you give a try to the new version and let me know if
it works fine on your side?

I have included the HTTP module you suggest in the new release. I
indicate in the FAQ how to use it to enable support for HTTP POST
instead of the piece of code in Global.asax. Thank you for your
suggestion!
I have also improved the FAQ to include hints at how to deal with POST
and URL rewriting.

Last but no the least, as you can see in the recent announcement in
this discussion group, PageMethods is now open source! Feel free to
contact me if you are interested in joining the project.

Regards,
Fabrice

Marco v. Frieling

unread,
May 13, 2007, 12:20:44 PM5/13/07
to PageMethods
Hello Fabrice,

that are really great news!

I'm sorry fr answering so late, but I was and still I'm very busy
because I have very much to do at university and work, and also for
www.imagineclub.at. The was "developed" based on the Clubsite Starter
Kit, when I got involved into the club and website development.
Because we have lots of ideas and features for it, I'm now porting the
code from the Website code model to the Web Application code model and
after that, I'll integrate PageMethods into that site. Then you'll
here from me again.

I'm interested in joining into the PageMethods project, but at the
moment I guess I have too much to do. Maybe I'll join the project
later on.

Regards,
Marco

Fabrice Marguerie

unread,
May 15, 2007, 6:58:21 PM5/15/07
to PageMethods
I know what busy means, so I understand perfectly how you feel :-)

Fabrice

Reply all
Reply to author
Forward
0 new messages