【发布时间】:2012-09-12 11:59:40
【问题描述】:
我正在使用 ASP.net 和 MVC3 。当会话过期时,我需要显示一个弹出窗口或转到登录页面。谁能告诉我如何重定向到操作名称为“index”且控制器名称为“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.");
}
【问题讨论】:
-
为什么要访问模型内部的HttpContext和Session?
-
你不需要从你的模型中重定向,你需要在控制器的 action 方法中这样做。
-
@nan:仅在此模型中,我正在检查用户凭据的授权。所以我只需要在这里重定向。
标签: c# asp.net-mvc asp.net-mvc-3