views:

263

answers:

3

Hello All,

Im using intelligencia urlrewriter as my url rewrite module. I have one very strange problem which only occurs when an url is rewritten but to make it more fun, not on all rewritten pages.

Edit: Forgot to tell you what's the problem boing boing. the problem is that my Page_Load event gets fired 2 times.

This is how my form rewrite adapter looks like:

using System;

using System.Web.UI; using System.Web; using System.Web.UI.WebControls;

public class FormRewriterControlAdapter : System.Web.UI.Adapters.ControlAdapter {

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{

    base.Render(new RewriteFormHtmlTextWriter(writer));

}

}

public class RewriteFormHtmlTextWriter : HtmlTextWriter {

public RewriteFormHtmlTextWriter(HtmlTextWriter writer)
    : base(writer)
{
    this.InnerWriter = writer.InnerWriter;
}

public RewriteFormHtmlTextWriter(System.IO.TextWriter writer)
    : base(writer)
{
    base.InnerWriter = writer;
}

public override void WriteAttribute(string name, string value, bool fEncode)
{

    // If the attribute we are writing is the "action" attribute, and we are not on a sub-control, 
    // then replace the value to write with the raw URL of the request - which ensures that we'll 
    // preserve the PathInfo value on postback scenarios 

    if ((name == "action"))
    {

        HttpContext Context = default(HttpContext);
        Context = HttpContext.Current;

        if (Context.Items["ActionAlreadyWritten"] == null)
        {

            // Because we are using the UrlRewriting.net HttpModule, we will use the 
            // Request.RawUrl property within ASP.NET to retrieve the origional URL 
            // before it was re-written. You'll want to change the line of code below 
            // if you use a different URL rewriting implementation. 

            value = Context.Request.RawUrl;

            // Indicate that we've already rewritten the <form>'s action attribute to prevent 
            // us from rewriting a sub-control under the <form> control 

            Context.Items["ActionAlreadyWritten"] = true;
        }

    }


    base.WriteAttribute(name, value, fEncode);

}

}

And this is how my web.config looks like

        <!-- Here the double page_load occurs  --> 
    <rewrite url="~/car-parts/(\d+)/(.+)" to="~/Products.aspx?type=parts&amp;iid=$1&amp;cid=9" />
    <rewrite url="~/car-stereo/(\d+)/(.+)" to="~/Products.aspx?type=stereo&amp;iid=$1&amp;cid=10" />



    <!-- this is working correctly -->
     <rewrite url="~/car-parts/browse-by-type/(\d+)/(.+)/(\d+)/(\d+)" to="~/Browse.aspx?cid=9&amp;type=country&amp;countryid=$1&amp;p=$3&amp;filter=$4" />

I have no idea where to look anymore, i checked my html markup since i've read that could couse this problem.

Kind regards, Mark

A: 

I wrote two short blog posts on UrlRewriting that might help

  1. Part One
  2. Part Two
rockinthesixstring
Nice articles you have there. It seems it was not having anything to do with the rewrite module.
Mark
A: 

Finally I found it, it was not having anything to do with the rewrite module , this is which caused the problem:

In one of my usercontrols i've used updateprogress

    <asp:UpdateProgress runat="server" AssociatedUpdatePanelID="upNewsletter" DisplayAfter="0">
    <ProgressTemplate>
        <asp:Image runat="server" ID="imgLoading" ImageUrl="~/Images/Template/loading.gif" />
    </ProgressTemplate>
</asp:UpdateProgress>

Now thats where the problem is , in the asp:Image tag. I've replaced it with a regular img tag and now everything works fine again. Took me some time to figure this out and I hope I can save you headache.

Kind regards

Mark
A: 

I've found this post searching for multiple page_loads, but I had the problem using a dynamically created CollapsePanel using a dynamically created Image. By filling the ImageUrl to a default image, the problem was solved.

header.Controls.Add( new Image
{
    ID = string.Format( "headerImage_{0}",  panelId ),
    EnableViewState = false,
    ImageUrl = "~/Images/collapse.jpg"
} );
Luuk