c# - How can I delete unavailable URL in browser history using C# .NET?
问题描述
I'm building an animal feed supplying website using C# .NET
It has those features below: http://localhost:52000/Account/Index =>show a list of accounts (ID, name...).
Click on an ID from Index page, it leads into Detail page: http://localhost:52000/Account/Details/6cc608a5-3b4b-4c6f-b220-3422c984919a
In account detail's page, it also has 2 buttons(functions): Delete account and Edit account information.
All I want is after deleting an account (in Detail view), website will redirect to the previous available page (Index,...). Therefore I use window.location.href = "/Account/Index/";
in Delete function.
Here is my delete function with redirecting solution:
function deleteAccount(id) {
var data = { 'id': id };
$.ajax({
*//....*
success: function (result) {
if (result) {
*//redirect to the previous page (Index)*
window.location.href = "/Account/Index/";
}
}
});
}
However,after deleting and redirecting to "/Account/Index/"
successfully, if Admin click on Back Button on Browser, website redirect to unavailable page (the Detail page of that deleted account: http://localhost:52000/Account/Detail/6cc608a5-3b4b-4c6f-b220-3422c984919a).
Then I tried to use window.history.back();
, window.history.go(-1);
, window.location.replace("/Account/Index/");
in turn instead, it worked perfectly only when Admin just deletes that account, if Admin Edits this account first then updates then deletes (Press Edit in Detail view -> Go to Edit view -> press Update -> Go back to Detail View )
--> website redirect to unavailable page (the editing page of that deleted account: 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/");
}
}
});
}
Is that possible to remove the unavailable URLs (those include ID of deleted account) in browser? How can I handle the Back Button in Browser to go through those unavailable URLs? (http://localhost:52000/Account/Detail/6cc608a5-3b4b-4c6f-b220-3422c984919a and http://localhost:52000/Account/Edit/6cc608a5-3b4b-4c6f-b220-3422c984919a)
解决方案
您可以尝试以下方法:
window.location.replace("/Account/Index/");
这相当于使用 Javascript 的 HTTP 重定向。
当您使用window.location.href
它时,就好像用户单击了一个链接,因此您可以在之后返回到以前的 URL。
推荐阅读
- asynchronous - 非阻塞异步方法在哪个线程上运行
- c# - 使用 C# 的电子邮件发送问题
- android - git push 后终端卡住了
- android - 如何使用矩形(左,上,右,下)将 OCR 文本设置为 PDF 文档内的画布?
- python - tf.layers.dense 如何创建 inputs.kernel 权重矩阵?
- css - Bootstrap 4 navbar-brand 中未显示字体真棒
- .net - EC2 上具有不同 IAM 角色的多个应用程序
- php - 合并两个数组并得到一个新数组
- xcode - 发布构建方案时 XCode 9.4.1 断点未命中
- jquery - Jquery 更改事件(或 URL 位置)在 iPhone(可能是移动设备)上不起作用