asp.net mvc Filter拦截跳转
2012-05-17 10:28
253 查看
在刚学mvc的时候 我一开始随便的做了拦截跳转,这样也实现了跳转 表面看起来完全没问题!
if (filterContext.HttpContext.Session["userId"] == null)
{
filterContext.HttpContext.Response.Redirect("~/LoginContent/Login", true);
}
但是某一天,突然调试了一下发现这个跳转 并不是及时的,而是会等把index的这个 action 执行,视图加载完毕才跳转!也是就是类似 在asp.net webform 里面 使用javascript做跳转!必须等到页面加载完毕,才会跳转!这样也就意味的 根本没有进行拦截!
if (filterContext.HttpContext.Session["userId"] == null)
{
filterContext.Result = new RedirectResult("~/LoginContent/Login");
base.OnActionExecuting(filterContext);
}
就把一句话进行改变,结果却与众不同!
if (filterContext.HttpContext.Session["userId"] == null)
{
filterContext.HttpContext.Response.Redirect("~/LoginContent/Login", true);
}
但是某一天,突然调试了一下发现这个跳转 并不是及时的,而是会等把index的这个 action 执行,视图加载完毕才跳转!也是就是类似 在asp.net webform 里面 使用javascript做跳转!必须等到页面加载完毕,才会跳转!这样也就意味的 根本没有进行拦截!
if (filterContext.HttpContext.Session["userId"] == null)
{
filterContext.Result = new RedirectResult("~/LoginContent/Login");
base.OnActionExecuting(filterContext);
}
就把一句话进行改变,结果却与众不同!
相关文章推荐
- asp.net mvc中在Filter中跳转千万不要使用Response.Redirect
- Asp.net mvc Filter 跳转
- asp.net mvc中在Filter中跳转千万不要使用Response.Redirect[转]
- ASP.NET MVC学习笔记-----Filter2
- Asp.Net MVC 进阶篇之Filter系列
- IoC容器Autofac(5) - Autofac在Asp.net MVC Filter中的应用
- ASP.NET MVC Filter (过滤器)的执行顺序
- asp.net mvc filter
- Asp.net Mvc Codeplex Preview 5 第二篇 Controller&Filter的新特性
- Asp.net Mvc Framework 十(测试方法及Filter的示例)
- asp.net mvc的Routing,Controller,Filter学习笔记
- 【ASP.NET MVC 学习笔记】- 12 Filter
- 返璞归真 asp.net mvc (5) - Action Filter, UpdateModel, ModelBinder, Ajax, Unit Test
- Asp.Net MVC中Action跳转(转载)
- Asp.Net MVC Filter权限过滤使用说明
- Asp.net MVC使用Filter解除Session, Cookie等依赖
- [导入]ASP.NET MVC框架开发系列课程(7):Action Filter.zip(16.83 MB)
- Asp.Net MVC 系列--进阶篇之Filter
- ASP.NET MVC学习笔记-----Filter
- Asp.net Mvc Framework 十(测试方法及Filter的示例)