gpt4 book ai didi

c# - 需要重定向到 asp.net MVC3 中的另一个页面

转载 作者:行者123 更新时间:2023-11-30 19:18:33 25 4
gpt4 key购买 nike

我正在使用 ASP.net 和 MVC3 。当 session 过期时,我需要显示一个弹出窗口或转到登录页面。谁能告诉我如何重定向到登录页面,该页面的操作名称为“index”, Controller 名称为“Home”。

我的代码是:

这个方法在我的模型中。在这个模型中我必须重定向到登录页面。

protected Product GetCurrentCorp(HttpContextBase context)
{

if (context.Session != null)
{
var selectedProduct = context.Session["SelectedProduct"];
if (selectedProduct != null)
{
var product= selectedProduct as Product;
return product;
}
}
// Here I need to redirect to index page(login page)
throw new ArgumentException("Product is not set, Cannot Continue.");
}

最佳答案

如果 LoggedOn 是您的 Action 而 Account 是您的 Controller 那么您可以将代码编写为:

return RedirectToAction("LoggedOn", "Account");

希望这对您有所帮助。!!!

关于c# - 需要重定向到 asp.net MVC3 中的另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12387713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com