PageMethod with Custom Handler
- by Mister Cook
I have a page based web method which works fine, using [WebMethod], i.e
[WebMethod]
public static void DoSomethingOnTheServer()
{
}
I also have a custom page handler to make SEO friendly URLs possible,
e.g
http://localhost/MySite/A_nice_url.ext = http://localhost/MySite/page.aspx?id=1
I am using Server.Transfer in my ProcessRequest handler to achieve this. This all works fine. Also, my page method works fine when the user requests the URL such as:
http://localhost/MySite/page.aspx?id=1
However, when the user requests the custom handled URL, i.e.
http://localhost/MySite/A_nice_url.ext
The client reports that the PageMethod has been successfully completed, but it has not been called at all.
I'm guessing it has something to do with my custom handler, so I have modified it to include PathInfo:
public void ProcessRequest(HttpContext context)
{
// ... (code to determine id) ...
// Transfer to the required page
string actualPath =
"~/page.aspx" + context.Request.PathInfo + "?id=" + determinedId;
context.Server.Transfer(actualPath);
}
So now if a PageMethod is called, it will result in:
http://localhost/MySite/page.aspx/DoSomethingOnTheServer?id=1
I'm wondering if this is the correct syntax for calling a PageMethod.
When I try Server.Transfer reports:
Error executing child request for /MySite/page.aspx/DoSomethingOnTheServer
I've experimented with HttpContext.RewritePath but not sure how to actually make it perform the request.
This does not seem to work, any ideas?