只有在访问page1.cshtml之后,Asp.net才允许访问page2.cshtml



我想阻止访问page2.cshtml的选项,并且只有在访问page1.cshtml后才允许它。我认为有一些代码可以添加到page2的控制器中,但我没有找到如何制作它。有什么帮助吗?

您可以使用TempData。在第一页中设置一个值,然后在第二页中进行检查。

public ActionResult FirstPage()
{
  TempData["Visited"] = true;
}
public ActionResult SecondPage()
{
  if(TempData["Visited"] != null)
    {
       //Do your logic. Clear the temp data if needed.
       return View("SecondPage");
    }
   return View("FirstPage");
}

最新更新