Fabrice's weblog

Tools and Source

News

My .NET Toolbox
An error occured. See the script errors signaled by your web browser.
No tools selected yet
.NET tools by SharpToolbox.com

Read sample chapters or buy LINQ in Action now!
Our LINQ book is also available on AMAZON

.NET jobs

Emplois .NET

transatlantys hot news

Contact

Me

Others

Selected content

PageMethods for VS 2005 released - well-defined URLs for your ASP.NET sites and applications

PageMethods for Visual Studio 2005 has just been released. This version offers the same support as the version for VS 2003, plus some additional features.
PageMethods proposes a new code model that enables well-defined URLs and simplifies working with hyperlinks for your ASP.NET sites and applications.

PageMethods enables reliable URLs.
Linking to a web page is very easy, both in simple HTML and in ASP.NET. Linking to a page that really exists, passing the right parameters, and parsing these parameters, is a bit different.
PageMethods takes care of your URLs. It proposes a solution to define structured URLs for each of your pages, as well as a clean and simple way to call them.
The idea is based on strict page inputs and declarative parameter binding. With PageMethods, each page exposes a set of methods that represent the different ways to call the page. All you have to do to start benefiting from sharp, reliable URLs is to add methods to your pages, and mark these methods with attributes provided by PageMethods.

Here is how you would declare a page method:

[PageMethod]
protected void DisplayCustomer(int customerID)
{
  ...
}

Here is how you would refer to the page declaring this method:

MyHyperLink.NavigateUrl = MyPageMethods.Customers.CustomerPage.DisplayCustomer(1234);


Features include:
  • Object-oriented approach for hyperlinks
  • No concatenations of strings required anymore
  • Strongly typed parameters
  • Automated parameter handling
  • Parameter validation
  • Compile-time checks
  • Code completion
  • Integrated with Visual Studio
  • Support for HTTP GET and HTTP POST (new)
  • Support for arrays and custom objects (new)
PageMethods is available for free.

Learn more on the dedicated site, where you'll find:
  • an introduction
  • a walkthrough tutorial
  • details about the features and benefits
  • and of course a page to download the product.
See http://metaSapiens.com/PageMethods

Don't forget to let me know what you think about the product, and what your experience with it is!

Comments

Colin Ramsay said:

The .zip file for VS2005 seems to be corrupt...
# November 28, 2005 7:55 AM

Fabrice said:

Colin, it works fine for me, and you are the first to report this.
I will try to send it to you by e-mail.
# November 28, 2005 8:02 AM

Lefti said:

Hi there,
I just installed PageMethods (VS2005 version) but it doesn't show up in the Add-In Manager. Someone a clue about this?

thx
# December 5, 2005 4:56 PM

Fabrice said:

Lefti,

Can you check that the following file exists?
"%ALLUSERSPROFILE%\Application Data\Microsoft\MSEnvShared\Addins\PageMethods.Addin"

If not, you can try to copy the file "C:\Program Files\metaSapiens\PageMethods for VS 2005\Addin\PageMethods.Addin" to "%ALLUSERSPROFILE%\Application Data\Microsoft\MSEnvShared\Addins\"

Could you send me your e-mail address using the contact page here so we can try to see what's wrong?
http://weblogs.asp.net/fmarguerie/contact.aspx
# December 5, 2005 5:10 PM

Fabrice said:

For information, the solution to this kind of problem is now described in the FAQ.
# December 6, 2005 7:40 PM

Lefti said:

Hello,
I just have one more issue/question regarding PageMethods: I noticed that calling an overloaded PageMethod method causes an exception at runtime. Is this known? is it a feature or a bug and should it be avoided?
Thanks,
Lefti
# December 7, 2005 2:53 PM

Lefti said:

One more: let's assume I have a page called login.aspx, which I want to be able to call i.e. optionally with a modifier like "ShowUnauthDetails" (which would display to unauthorized users who tried to access previously a closed area an additional message).

Calling the page without this modifier (for users calling it the first time in order to login), should not show this message.

What I did: I tried implementing a Display PageMethod method (not default). What I get when I call the page login.aspx directly through the browser (i.e. not by redirecting with MyPageMethods.Login.Display(True)) is a "Check URL Bad parameters" exception or similar message.

Maybe I misunderstood sth.? The code samples are very good but I'm afraid they didn't help me regarding this. A hint or a small explanation would be great.
Thx again for your time
# December 7, 2005 3:07 PM

Fabrice said:

Hello Lefti,

Method overloads are not currently supported by PageMethods. I may work on this in a future version, but for the moment this means that you cannot have to page methods with the same name in one page. You have to give your methods different names like "DisplayDefault" and "DisplayUnauth".
This is a known limitation, but I hadn't not added it to the FAQ yet. I have now :-)

Reagarding your second question...
If your Login page inherits from MetaSapiens.PageMethods.BasePage, and if you go to login.aspx without a method name in the URL, you will get the "Bad web page invocation. Check the URL parameters." exception you have seen.
To avoid this, you have two solutions:
1) don't inherit from MetaSapiens.PageMethods.BasePage, but add the following code to the Page_Load method:

if (!IsPostBack)
PageMethodsEngine.InvokeMethod(this, false);

or

2) add a default page method that would handle this case, in addition to your Display method. You also have to add a constructor like this to specify that you want the default method to be handled:
public YourPage : base(true)
{
}

--
To help you understand what happens, here is the code that is executed automatically by MetaSapiens.PageMethods.BasePage during Load:

if (!IsPostBack)
if (!PageMethodsEngine.InvokeMethod(this, _HandleDefaultMethod))
throw new PageMethodsException("Bad web page invocation. Check the URL parameters.");

You can see that an exception is thrown if no page method is found. This is not what you want in your case.

Is this ok with you?
# December 7, 2005 6:45 PM

Lloyd said:

If I understand the URLFormat, it's only if you are doing URL Rewrites it doesn't rewrite them for you. Is that right? If so, do you have any plans on implementing a URL rewrite system that would leverage all of the PageMethods knowledge of the pages it's calling?

I love the tool but I was really hoping it would rewrite the URLS too as dirty querystrings are my real problem.
# December 9, 2005 11:16 AM

Fabrice said:

Lloyd,

Yes, support for URL rewriting (not just URL formatting) is planned for a future release due for the first quarter of 2006. Other improvements will concern security, such as tamper-proof URLs.
This will be PageMethods Pro, a commercial edition. But not too expensive :-)

In the meantime, you can take a look at Global.asax in the demos and here:
http://weblogs.asp.net/fmarguerie/archive/2004/11/18/265719.aspx
http://msdn.microsoft.com/library/en-us/dnaspp/html/urlrewriting.asp
http://pietschsoft.com/Blog/archive/2005/11/12/762.aspx
# December 9, 2005 12:42 PM

Lloyd said:

Excellent to hear!! You will definitely have a saleable item with that.

Also, thanks for the demos.
# December 9, 2005 1:44 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)