如何防止代码修改浏览器历史记录?

本文关键字:历史 记录 浏览器 修改 何防止 代码 | 更新日期: 2023-09-27 18:17:00

下面是aspx的设置。当我修改下拉列表时,一个项目被添加到我的浏览器的历史记录中,这导致不必要的"返回"点击来转义页面。

如何防止aspx修改浏览器的历史记录?

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="RealTimeTracking.aspx.cs" Inherits="RealTimeTracking" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <title>Real Time Tracking</title>
    <script type="text/javascript">
        function UpOneLevel() {
            window.location.href = "TableofContents.aspx";
        }
    </script>
    <link href="Calender/Style/calendar-blue.css" rel="stylesheet" type="text/css" />
    <script language="javascript" src="Calender/calendar.js" type="text/javascript"></script>
    <script language="javascript" src="Calender/calendar-setup.js" type="text/javascript"></script>
    <script type="text/javascript" src="Calender/lang/calendar-en.js"></script>
</asp:Content>
<asp:Content ID="masterBody" ContentPlaceHolderID="body" runat="server">
    <h2 class="text">
        Real Time Tracking</h2>
    <h3 class="text">
        Select a Unit</h3>
    <h5 class="userinfotable">
        Phone:
        <asp:Label ID="lbl_PhoneValue" runat="server"></asp:Label></h5>
    <h5 class="userinfotable">
        Client:
        <asp:Label ID="lbl_ClientValue" runat="server"></asp:Label></h5>
    <asp:Label ID="lblErrormsg" runat="server" CssClass="words"></asp:Label>
    <table class="tbusernamepassword" style="text-shadow: none; color: Black; font-size: .9em; text-align: center;">
        <tr>
            <td>
                <asp:Label ID="txtPleaseSelect" runat="server" CssClass="words" Style="padding: 0px;">
                    Please Select an Asset from the drop down menu.</asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="lblMsg" runat="server" CssClass="vedispMsg"></asp:Label>
                <asp:DropDownList ID="DropSelectUnit" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropSelect_SelectedIndex"
                    OnLoad ="DropSelect_SelectedIndex"
                    DataTextField="Text" 
                    DataValueField="Value"
                    CssClass="tdsubmitbutton" Width="100%">
                </asp:DropDownList>
            </td>
        </tr>
    </table>
    <asp:Button ID="GoButton" runat="server" Text="Go To Map" OnClick="GoButton_Click" CssClass="tdsubmitbutton" Width="130px" />
    <p>
        &nbsp;
    </p>
    <p>
        &nbsp;
    </p>
    <asp:PlaceHolder runat="server" OnLoad="PingRateTable">
    <table class="tbusernamepassword" style="text-shadow: none; color: Black; font-size: .9em; text-align: center;padding-bottom:2px;">
        <tr>
            <td>
                <asp:Label ID="Label1" runat="server" CssClass="words" Style="padding: 0px;">
                    Select a Ping Rate.</asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="Label2" runat="server" CssClass="vedispMsg"></asp:Label>
                <asp:DropDownList ID="PingRate" runat="server" AutoPostBack="true" OnSelectedIndexChanged="PingRate_SelectedIndex"
                    OnLoad ="PingRate_SelectedIndex"
                    CssClass="tdsubmitbutton" Width="100%">
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="PingButton" runat="server" Text="Set Ping Rate" OnClick="PingButton_Click" CssClass="tdsubmitbutton" Width="130px" />
            </td>
        </tr>
    </table>
    <table class="tbusernamepassword" style="text-shadow: none; color: Black; font-size: .9em; text-align: center;padding-top:0px;">
        <tr>
            <td>
                <asp:Label ID="IsPingSet" runat="server" CssClass="words" Style="padding: 0px;"></asp:Label>
            </td>
        </tr>
    </table>
    </asp:PlaceHolder>
    <div style="visibility:hidden;">
        <input type="text" id="formlatitude" name="latitude" />
        <input type="text" id="formlongitude" name="longitude" />
        <input type="text" id="formassetname" name="asset" />
        <input type="text" id="formdatetime" name="dateandtime" />
        <input type="text" id="formaddress" name="address" />
    </div>
</asp:Content>
后台代码c#

protected void Page_Load(object sender, EventArgs e)
{
    Common.CheckAnyLogin();
    Session["Action"] = Request.Url;
    AssetHelper assethelp = new AssetHelper();
    IsPingSet.Text = "";
    if (!IsPostBack)
    {
    }
}

protected void DropSelect_SelectedIndex(object sender, EventArgs e)
{
    if (sender.GetType().Name == "DropDownList")
    {
        Session["UnitName"] = ((DropDownList)sender).SelectedItem;
        Session["SerialNo"] = ((DropDownList)sender).SelectedValue;
    }
}

Master.master

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--This master page encompasses all pages that require the user to be logged in.
This means that WhatIsThis.aspx, Logoff.aspx, Default.aspx,
 SearchForAsset-Map.aspx, MyLocation-Map.aspx,
 FleetTracking-Map.aspx, and AssetHistory-Map.aspx are not included in this masterpage.-->
<head runat="server">
<!--Apple iPhone and iPad compatibility-->
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <link rel="apple-touch-startup-image" href="images/splashscreen.png" />
    <link rel="apple-touch-icon" href="images/Sights57.png" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
    <meta name="format-detection" content="telephone=no" />
<!--Microsoft Bing Maps-->
    <script type="text/javascript" src="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&s=1"></script>
    <script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="/js/jquery-bing-maps/jquery.ui.bmap.js"></script>
<!--CSS and Javascript-->
    <link rel="stylesheet" href="css/login.css" />
    <link rel="stylesheet" href="css/navbuttons.css" />
    <script type="text/javascript" src="js/topofpage.js"></script>
    <asp:ContentPlaceHolder id="head" runat="server"></asp:ContentPlaceHolder>
</head>
<body style="min-height:391px;" runat="server" id="masterbody">
<form id="wholepageform" runat="server">
<div id="topofpage">
<!--#include virtual="header.html"-->
<div style="height:43px;"><br /></div>
<div class="undersightslogo" id="undersightslogo">
    <asp:ContentPlaceHolder id="body" runat="server"></asp:ContentPlaceHolder>
    <div id="copyright"><h6>
    &copy; Reltronics Technologies <script type="text/javascript">document.write(new Date().getFullYear());</script>
    </h6></div>
</div>
</div>
</form>
</body>
</html>

header.html只是一个包含我的头,包括我的UpOneLevel按钮

谢谢。

如何防止代码修改浏览器历史记录?

设置AutoPostBack="false"应该可以解决您的问题。