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

发布于 2024-10-17 04:17:07 字数 3589 浏览 4 评论 0原文

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

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

有没有什么方法可以阻止 asp.net 重新附加实际已经存在但使用 IIS 重写的查询字符串

实时链接 <- 提交评论,然后通过单击地址栏刷新页面(编辑)!美丽的黄色错误消息。

编辑

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>

I am developing a simple rating system for my employer's profile based web-app. Here is my problem:

  • The actual page is domain.com/review.aspx?user=username, but I use the url-rewrite module in IIS to use domain.com/username/review
  • The page contains a repeater control that displays reviews for that username, as well as a form for people to create new reviews
  • When the form is submitted, asp.net re-appends the (hidden) querystring to the url on postback.
  • The post-back url is now domian.com/username/review?user=username&review, causing the page to break if refreshed.

Is there any way to keep asp.net from re-appending the querystrings that are actually already present, but re-written with IIS

Live link <- submit a review, and then refresh the page (edit) by clicking in the address bar! Beautiful yellow error message.

EDIT

C# code:

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 code:

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北斗星光 2024-10-24 04:17:07

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

I believe you need to set the Page's Form.Action property to the same remapped URL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文