如何使用 C# .NET 删除浏览器历史记录中不可用的 URL?

How can I delete unavailable URL in browser history using C# .NET?

我正在使用 C# .NET 构建一个动物饲料供应网站

它具有以下特点: http://localhost:52000/Account/Index =>显示帐户列表(ID、名称...)。

点击 索引页面 中的 ID,它会进入 详情页面 http://localhost:52000/Account/Details/6cc608a5-3b4b-4c6f-b220-3422c984919a

在账户详情页面,它还有2个按钮(功能):删除账户和编辑账户信息。

我想要的只是在删除帐户后(在详细视图中),网站将重定向到以前的可用页面(索引,...)。因此我在删除函数中使用 window.location.href = "/Account/Index/";

这是我的带有重定向解决方案的删除函数:

function deleteAccount(id) {
            var data = { 'id': id };
            $.ajax({
                *//....*

                success: function (result) {
                    if (result) {
                         *//redirect to the previous page (Index)*
                         window.location.href = "/Account/Index/";
                    }
                }
            });
        }

但是,在成功删除并重定向到 "/Account/Index/" 后,如果管理员单击浏览器上的 返回 按钮,网站将重定向到不可用的页面(已删除的详细信息页面帐户:http://localhost:52000/Account/Detail/6cc608a5-3b4b-4c6f-b220-3422c984919a)。

然后我尝试依次使用 window.history.back();window.history.go(-1);window.location.replace("/Account/Index/");,只有当管理员删除该帐户时,它才能完美运行,如果管理员先编辑此帐户然后更新然后删除(Press Edit in Detail view -> Go to Edit view -> press Update -> Go back to Detail View ) --> 网站重定向到不可用页面(被删除帐户的编辑页面:http://localhost:52000/Account/Edit/6cc608a5-3b4b-4c6f-b220-3422c984919a)。

function deleteAccount(id) {
            var data = { 'id': id };
            $.ajax({
                *//....*

                success: function (result) {
                    if (result) {
                         *//redirect to the previous page (Index)*
                         window.history.back(); 
                         // or window.history.go(-1)
                         //or window.location.replace("/Account/Index/");
                    }
                }
            });
        }

是否可以删除浏览器中不可用的网址(包括已删除帐户的 ID)?如何处理浏览器中的后退按钮以浏览那些不可用的 URL? (http://localhost:52000/Account/Detail/6cc608a5-3b4b-4c6f-b220-3422c984919ahttp://localhost:52000/Account/Edit/6cc608a5-3b4b-4c6f-b220-3422c984919a)

您可以尝试以下方法:

window.location.replace("/Account/Index/");

这相当于使用 Javascript 的 HTTP 重定向。

当您使用 window.location.href 时,就好像用户点击了 link,因此之后您可以返回到之前的 URL。