Ugly URLs with MCMS and ASP.NET 2.0

Today a newsgroup post reminded me that I did not yet publish the necessary changes for my Http Module that corrects the Ugly MCMS URLs caused by ASP.NET postbacks when ASP.NET 2.0 master pages are used.

The HttpModule I published earlier does not work in this scenario as it relies on the fact that a HtmlForm control exists in the root control collection.

This is not the case for ASP.NET master pages! Here you will find the HtmlForm control in a child collection of the MasterPage control.

And an additional problem occurs: with MasterPages I found that the ID of the HtmlForm control will not be the ID rendered in the html content. So we cannot retrieve the ID in the same way as with ASP.NET 1.1 or with ASP.NET 2.0 without master pages.

Thanks to the developers of ASP.NET it is now much easier to find the HtmlForm being used by ASP.NET: the javascript variable theForm is set with the required value.

This allows us to simplify the OnInit method of the HttpModule:

public void OnInit(object sender, EventArgs eventArgs)
    System.Web.UI.Page currentPage = sender as System.Web.UI.Page;

    if (currentPage.Request.UserAgent.IndexOf("Mac_PowerPC") > 0)
        currentPage.RegisterClientScriptBlock("__CMS_Page",        // now lets register our script with the nice URL
            "<script language=\"javascript\" type=\"text/javascript\">\n"+
            "   var __CMS_PostbackForm = theForm;\n" +
            "   var __CMS_CurrentUrl = \"" + CmsHttpContext.Current.ChannelItem.Url + "\";\n" +
            "   __CMS_PostbackForm.action = __CMS_CurrentUrl;\n" +
            "// -->\n"+

A small caveat exists: this version of the httpmodule is no longer compatible with ASP.NET 1.1.

Comments (13)

  1. George Leithead says:

    Was it my post in the news group that prompted you? 🙂

  2. Hi George,

    indeed it was your post.



  3. hi stefan,

    how to inherit and override the AuthoringSaveNewAction abstract class.

  4. Hi Bhargava,

    the comment section is only intended to be used for question or comments for the article.

    Please post general MCMS questions into the public newsgroup microsoft.public.cmserver.general

    I will answer them there.



  5. Jennifer says:

    Hi Stefan,

    How would I maintain query strings and control state/view state during post backs?  I notice that it takes the form name and replaces the action with the posting Url.



  6. Hi Jennifer, the behaviour with this module should be the same as without it.

  7. Sandro Mastronardi says:

    Hi Stefan,

    I have a solution for .NET 1.1 that works without javascripts, I haven’t had the time yet to make it .NET 2.0 compatible, but that must be very easy to achieve.  You can find it here:

    Hope you like it, let me know your toughts.


  8. Shyamala says:

    Hi stefen,

    we are creating and updating the posting from admin. if i dispose the CmsApplicationContext i am getting this error.

    Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

    If i didn’t dispose i am getting ODBC error.

    what the issue?



  9. Hi Shyamala,

    please open a support case for this. This is not a known problem.



  10. Jannik Anker says:

    Hi Stefan,

    How strange. I just found this little (important) fix, and couldn’t understand why I couldn’t make it work. That is, until I realized it only works when using currentPage.RegisterClientScriptBlock(…), not when using the more correct currentPage.ClientScript.RegisterClientScriptBlock ??? I tried putting both this.GetType() and currentPage.GetType() as first parameter, but neither worked.

    Do you have any idea why this is?

  11. Hi Jannik,

    the reason is that MCMS itself uses currentPage.RegisterClientScriptBlock to register a different script using this id. My script overwrites this script. Using the other method will not overwrite the script from MCMS but add it as additional script which will not lead to the desired results.



  12. Jannik Anker says:

    Ah, okay. That makes sense – thanks!

  13. Anonymous says:

    As some of you already noticed: GotDotNet is now down and the code samples previously hosted there have

Skip to main content