浏览器历史记录中的RedirectToAction和HTML.ActionLink页面

时间:2014-03-18 19:05:53

标签: c# asp.net-mvc-4

我在MVC 4中的global.asax中使用以下代码来限制页面在浏览器历史记录中并且它按预期工作:

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的操作,该操作返回一个视图(Constants.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);
        }
    }

这是Cycles动作:

        [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);
    }

以下是我认为的代码:

            @Html.ActionLink("Return to Cycle List", "Cycles", "NSQIP")

我已经看到很多关于隐藏浏览器历史记录的帖子,但没有用RedirectToAction或Html.ActionLink来解决这个问题。

我的问题是,如何从浏览历史记录中限制这些观点?

非常感谢!!!

0 个答案:

没有答案
相关问题