如何阻止asp.net在表单上重新附加查询字符串?

时间:2011-02-11 17:53:52

标签: c# asp.net postback request.querystring

我正在为我的雇主基于个人资料的网络应用开发一个简单的评级系统。这是我的问题:

  • 实际页面为domain.com/review.aspx?user=username,但我使用IIS中的url-rewrite模块来使用domain.com/username/review
  • 该页面包含一个转发器控件,用于显示该用户名的评论,以及一个供人们创建新评论的表单
  • 提交表单后,asp.net会在回发时将(隐藏的)查询字符串重新附加到网址。
  • 回传网址现为domian.com/username/review?user=username&review,导致刷新页面时会中断。

有没有办法让asp.net重新附加实际已经存在的查询字符串,但是用IIS重写了

Live link< - 提交评论,然后点击地址栏刷新页面(编辑)!美丽的黄色错误消息。

修改

C#代码:

protected void submitReview(object sender, EventArgs e)
    {
        try
        {
            int starRating = txtStarRating.Text == "" ? 0 : Int32.Parse(txtStarRating.Text);
            testimonials.addNew(Int32.Parse(txtHiddenUid.Text), reviewContent.Text, reviewerName.Text, true, starRating);
            reviewForm.Visible = false; pnlReviewSubmissionSuccess.Visible = true;
        }
        catch { starErrorMessage.Text = "There was an error submitting your review. Please refresh this page and try again."; }
    }

ASP代码:

<div ID="pnlSubmitReview" runat="server">
                <div id="reviewForm" runat="server">
                    <div id="leaveReviewBoxes">
                        <span style="margin-bottom:10px; float:left; font-weight:bold;">Leave a Review</span>
                        <div style="clear:both;"></div>
                        <asp:Label ID="nameLabel" runat="server">Name:</asp:Label>            
                        <asp:Textbox runat="server" ID="reviewerName"></asp:Textbox>
                        <div style="clear:both;"></div>
                        <asp:Label ID="reviewLabel" runat="server">Review:</asp:Label>
                        <asp:Textbox runat="server" ID="reviewContent" Width="200px" TextMode="MultiLine"></asp:Textbox>
                    </div>

                    <div>
                        <ol id="starlist"> 
                            <li><a id="star1" name="star1" href="javascript:void(0)" class="star"></a></li>
                            <li><a id="star2" name="star2" href="javascript:void(0)" class="star"></a></li>
                            <li><a id="star3" name="star3" href="javascript:void(0)" class="star"></a></li>
                            <li><a id="star4" name="star4" href="javascript:void(0)" class="star"></a></li>
                            <li><a id="star5" name="star5" href="javascript:void(0)" class="star"></a></li>
                        </ol>
                        <asp:TextBox ID="txtStarRating" runat="server" Text=""></asp:TextBox>            
                        <asp:Label runat="server" ID="starErrorMessage"></asp:Label>
                        <asp:TextBox ID="txtHiddenUid" runat="server" Visible="false"></asp:TextBox>
                    </div>
                    <asp:Button runat="server" ID="submitReviewButton" Text="Submit Review" OnClick="submitReview" />
                </div>

                <div ID="pnlReviewSubmissionSuccess" runat="server" Visible="false">
                        Thank you! Your review has been submitted.
                </div>
            </div>

1 个答案:

答案 0 :(得分:7)

我认为您需要将Page的Form.Action属性设置为相同的重新映射的URL。