Click here to Skip to main content
15,887,175 members
Articles / Web Development / HTML

How to Make Anthem Ajax Work With URL ReWriting

Rate me:
Please Sign up or sign in to vote.
3.36/5 (10 votes)
24 Mar 2008GPL32 min read 44.3K   1.1K   84   4
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, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior) ConvexDigital Software Solutions
India India
My name is Anurag Dwivedi.
I live in Noida, India.
Feel free to contact me
at topanurag@gmail.com.
Programming is my passion.
Currently I am doing problem shooting
for my parent organisation: http://convexdigital.com.
Wish Happy Programming To All The Readers Smile | :)


Comments and Discussions

 
GeneralMy vote of 5 Pin
Global Analyser4-Jun-13 18:11
Global Analyser4-Jun-13 18:11 
BugThis simply doesnt work Pin
Yashar Mortazavi22-Sep-12 5:41
Yashar Mortazavi22-Sep-12 5:41 
GeneralMy vote of 1 Pin
Yashar Mortazavi22-Sep-12 3:19
Yashar Mortazavi22-Sep-12 3:19 
QuestionUsage of classes?! Pin
Yashar Mortazavi22-Sep-12 3:09
Yashar Mortazavi22-Sep-12 3:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.