C# 浏览器历史记录中的RedirectToAction和HTML.ActionLink页面
我在MVC 4中的global.asax中使用以下代码来限制页面出现在浏览器历史记录中,并按预期工作:C# 浏览器历史记录中的RedirectToAction和HTML.ActionLink页面,c#,asp.net-mvc-4,C#,Asp.net Mvc 4,我在MVC 4中的global.asax中使用以下代码来限制页面出现在浏览器历史记录中,并按预期工作: protected void Application_BeginRequest() { Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetAllowResponseInBrowserHistory(false); Response.Cac
protected void Application_BeginRequest()
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetAllowResponseInBrowserHistory(false);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();
}
但是,通过RedirectToAction和@Html.ActionLink加载的页面仍然可以通过浏览器历史记录进行访问。例如,控制器中的我的登录代码验证用户,如果有效,则重定向到名为Cycles的操作,该操作返回视图常量。cyclesActionName=Cycles:
[Authorize]
public ActionResult SubmitLogin(LoginViewModel model)
{
Login userLogin = new Login();
bool loginSuccessful = userLogin.LoginUser(Constants.domainName, model.UserName, model.Password);
if (string.IsNullOrEmpty(model.Password) || (string.IsNullOrEmpty(model.UserName)))
{
return RedirectToAction(Constants.loginActionName);
}
if (loginSuccessful)
{
return RedirectToAction(Constants.cyclesActionName);
}
else
{
ViewData[Constants.messageBoxIndex] = Constants.loginFailureString;
return View(Constants.loginActionName, model);
}
}
以下是循环动作:
[Authorize]
public ActionResult Cycles()
{
SortOrder initSortOrder = new SortOrder();
System.Web.HttpContext.Current.Session[Constants.sortOrderSessionName] = initSortOrder;
List<Cycle> Cycles = new FileMethods().GetCycles(ConfigurationManager.AppSettings[Constants.cycleFileLocationFromWebConfig]);
CycleViewModel model = new CycleViewModel();
model.Cycles = Cycles.OrderByDescending(x => x.StartDate).ToList();
System.Web.HttpContext.Current.Session[Constants.cycleSessionName] = Cycles;
return View(Constants.cyclesActionName, model);
}
我看过很多关于隐藏浏览器历史的文章,但是没有一篇是用RedirectToAction或Html.ActionLink来解决这个问题的
我的问题是,如何从浏览历史记录中限制这些视图
非常感谢 你说的浏览器历史是什么意思?这是在浏览器的后退按钮中使用的按钮吗?或者URL文本框中的自动完成功能?我指的是IE中历史记录Ctrl+H中列出的内容。我没有意识到它与后退按钮中的内容不同。
@Html.ActionLink("Return to Cycle List", "Cycles", "NSQIP")