0
如何将程序流重定向到控制器操作。我想模拟Global.asax.cs中的MVC的RedirectToAction(“ActionName”,“ControllerName”,路由值)调用。我该怎么做?ASP.NET MVC Global.asax中的会话超时处理
如何将程序流重定向到控制器操作。我想模拟Global.asax.cs中的MVC的RedirectToAction(“ActionName”,“ControllerName”,路由值)调用。我该怎么做?ASP.NET MVC Global.asax中的会话超时处理
如果您使用的是MVC 3,我推荐使用writing your ownactionfilter,然后您可以使用apply globally。
一个小的代码示例:
public class HandleSessionTimeoutAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(FilterExecutingContext filterContext)
{
// Do whatever it is you want to do here.
// The controller and request contexts, along with a whole lot of other
// stuff, is available on the filter context.
}
}
,然后在Global.asax.cs:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
// Register global filter
GlobalFilters.Filters.Add(new HandleSessionTimeoutAttribute());
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
看起来这正是我需要的。将尝试一下,并将其标记为答案 – Robylaz