Im utilisant intelligencia urlrewriter comme module de réécriture d'URL. J'ai un problème très étrange qui se produit seulement quand une URL est réécrite mais pour la rendre plus amusante, pas sur toutes les pages réécrites.ASP.NET Événements multiples Page_Load avec réécriture d'URL
Edit: oublié de vous dire quel est le problème Boing Boing. le problème est que mon événement Page_Load est renvoyé 2 fois.
Voici comment ma forme adaptateur rewrite ressemble:
using System;
using System.Web.UI; en utilisant System.Web; en utilisant 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);
}
}
Un d voilà comment mon web.config ressemble
<!-- Here the double page_load occurs -->
<rewrite url="~/car-parts/(\d+)/(.+)" to="~/Products.aspx?type=parts&iid=$1&cid=9" />
<rewrite url="~/car-stereo/(\d+)/(.+)" to="~/Products.aspx?type=stereo&iid=$1&cid=10" />
<!-- this is working correctly -->
<rewrite url="~/car-parts/browse-by-type/(\d+)/(.+)/(\d+)/(\d+)" to="~/Browse.aspx?cid=9&type=country&countryid=$1&p=$3&filter=$4" />
Je ne sais pas où plus regarder, j'ai vérifié mon code html depuis que je l'ai lu cela pourrait couse ce problème.
Meilleures salutations, Mark
Vous n'avez pas dit quel est le problème très étrange. –