Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to Make Anthem Ajax Work With URL ReWriting

0.00/5 (No votes)
24 Mar 2008 1  
How To Make Anthem Ajax Work With Url ReWriting

Introduction

Anthem Ajax is one of the best Ajax libraries available to write Ajax without writing JavaScript in ASP.NET. But attempting to combine it with Extensionless URL ReWriting is quite a challenge.

You can download Anthem Ajax from here. You can read more about the URL ReWriting Tool used from here.
The Form control used is an extension of this article.

Background

In the current web development scenario, the two most desirable goodies are:

  1. Ajax: giving no postbacks, and
  2. UrlReWriting: Giving SEO friendly, beautiful URLs

But it has been quite difficult to use both of them together.

The Ajax breaks down whenever there is URL of the form: http://foo.com/id/151. To overcome this problem, I tackled it with a strategy to provide different views of the same URL to the HTML form and to the Ajax Framework.

The Solution

Towards uniting Anthem Ajax with smooth URLs, my strategy was to provide different views of the same URL to the HTML form and to the Ajax Framework. I wanted the action attribute of the form to have the original RawUrl as its value. While I wanted the Anthem Ajax framework to have the ReWritten Simple URL as its value.

I created a new Form Class by inheriting it from HtmlForm Class. Then I wrote the original URL (URL without ReWriting) in the name attribute of the form. And in the action Attribute, the Raw URL (beautiful Url, as it appears in the Address Bar).

Then, I made one change in the anthem.js file of the Anthem Download. I made the function Anthem_GetCallBackUrl return URL from form.name instead of form.action.

This solves the two problems:

  1. The Action attribute of the form will have the original beautiful Extensionless URL (Raw URL).
    This will help to preserve the beautiful Extensionless URL even after page PostBacks (like those caused by button clicks).
  2. While the Name Attribute will have the ReWritten Real URL.
    This will be supplied to the Anthem Framework, making it believe that it is working without any URL ReWriting :-)

Using the Code

To see a live demo, simply run the attached sample website.

To do URL ReWriting in a project:

  1. Just include the DLLs in the Folder: ReWriting DLLs
  2. Use the Anthem Library (the DLL in the above folder) contained with this project.
  3. Make your Web.Config as shown in the attached Web.Config file.
  4. Instead of using the form tags in the .aspx files, use the inherited form's tags.

History

  • 24th March, 2008: Initial version

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here