友好的网址导致双页输入

时间:2013-03-11 19:28:54

标签: c# asp.net

我正按照此页面上的说明尝试制作一个友好的网址:TipTrickURL, 为了将www.samplepage.com/Default.aspx?Category=Desserts&Page=4更改为 www.samplepage.com/Default.aspx/Desserts/Page4 。但是,每次我输入友好的URL时,它都会进入页面两次。我不能说这是一个回发,因为它进入验证if(!IsPostBack)并且它发生在我尝试的每个页面上,复杂页面和仅文本页面。

如何阻止此双页输入?

ASPX代码

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ResultPool.aspx.cs" Inherits="Drawit.ResultPool" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <link href="Content/Site.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <ul>
        <li class="labelForm"><asp:Label ID="lblResult" runat="server" Text=""></asp:Label></li>
        <li class="labelForm"><asp:Label ID="lblOriginal" runat="server" Text=""></asp:Label></li>

        <li class="labelForm"><asp:Button ID="btnHome" runat="server" Text="Button" OnClick="btnHome_Click" /></li>
    </ul>
</asp:Content>

.CS代码

public partial class ResultPool:System.Web.UI.Page {

protected void Page_Load(object sender, EventArgs e)
{
    string Mensaje = "El proceso de ";
    string RutaArchivo = "~/Images/Results/";
    if (!IsPostBack)
    {
        try
        {
            string stats;
            if (Request.PathInfo.Length > 0)
                stats = Request.PathInfo.Substring(1);
            else
                stats = "Error";

            string[] result = stats.Split('/');
            stats = result[0];

            switch (stats)
            {
                case "OK":
                    {
                        Mensaje += result[1] + " ha finalizado con exito!";
                        break;
                    }
                case "NO":
                    {
                        Mensaje += result[1] + " ha tenido un error y no pudo finalizar!";
                        break;
                    }
                case "Error":
                    {
                        Mensaje = "Ha ocurrido un error. Por favor intente mas tarde.";
                        break;
                    }
                default:
                    {
                        Mensaje = "Ha ocurrido un error. Por favor intente mas tarde.";
                        break;
                    }
            }
            lblResult.Text = Mensaje;
        }
        catch (Exception)
        {
            lblResult.Text = "There was an error!";
        }

    }
}

0 个答案:

没有答案