Asp.net mvc Global.asax中的ASP.NET MVC会话超时处理

Asp.net mvc Global.asax中的ASP.NET MVC会话超时处理,asp.net-mvc,asp.net-mvc-2,Asp.net Mvc,Asp.net Mvc 2,如何将程序流重定向到控制器操作。我想在Global.asax.cs内模拟MVC的RedirectToAction(“ActionName”、“ControllerName”、route values)调用。我该怎么做呢?如果您使用的是MVC 3,我建议您使用,然后您可以使用 一个小代码示例: public class HandleSessionTimeoutAttribute : ActionFilterAttribute { public override void OnActionE

如何将程序流重定向到控制器操作。我想在Global.asax.cs内模拟MVC的RedirectToAction(“ActionName”、“ControllerName”、route values)调用。我该怎么做呢?

如果您使用的是MVC 3,我建议您使用,然后您可以使用

一个小代码示例:

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

如果您使用的是MVC3,我建议您使用它,然后您可以使用它

一个小代码示例:

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

看来这就是我需要的。我会尝试一下,并将此标记为答案。看起来这就是我需要的。我稍后会尝试一下,并将此标记为答案