0

我使用intelligencia urlrewriter 作为我的url 重写模块。我有一个非常奇怪的问题,它只在重写 url 时发生,但为了让它更有趣,而不是在所有重写的页面上。

编辑:忘了告诉你boing boing有什么问题。问题是我的 Page_Load 事件被触发了 2 次。

这就是我的表单重写适配器的样子:

using System;

使用 System.Web.UI;使用 System.Web;使用 System.Web.UI.WebControls;

公共类 FormRewriterControlAdapter : System.Web.UI.Adapters.ControlAdapter {

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

    base.Render(new RewriteFormHtmlTextWriter(writer));

}

}

公共类 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);

}

}

这就是我的 web.config 的样子

        <!-- 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" />

我不知道再去哪里看,我检查了我的 html 标记,因为我读过这可能会导致这个问题。

亲切的问候,马克

4

3 回答 3

1

当我在我的规则中使用这个重写规则时,这个问题已经解决了:

<rewrite url="^(/.+(\.gif|\.flv|\.swf|\.png|\.jpg|\.ico|\.pdf|\.doc|\.xls|\.css|\.zip|\.rar|\.js|\.xml|\.mp3)(\?.+)?)$" to="$1" processing="stop" />

但请记住在所有 .css/.js/.jpg/... 规则之后使用此规则。

于 2013-03-05T11:38:44.853 回答
0

最后我找到了,它与 rewrite 模块没有任何关系,这是导致问题的原因:

在我的一个用户控件中,我使用了 updateprogress

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

现在这就是问题所在,在 asp:Image 标记中。我已经用常规的 img 标签替换了它,现在一切都正常了。我花了一些时间来解决这个问题,我希望我可以让你头疼。

亲切的问候

于 2010-02-18T19:10:43.510 回答
0

我发现这篇文章正在搜索多个 page_loads,但我在使用动态创建的图像的动态创建的 CollapsePanel 时遇到了问题。通过将 ImageUrl 填充为默认图像,问题得到解决。

header.Controls.Add( new Image
{
    ID = string.Format( "headerImage_{0}",  panelId ),
    EnableViewState = false,
    ImageUrl = "~/Images/collapse.jpg"
} );
于 2010-09-03T10:16:48.323 回答