问题描述:
我登陆进系统主页,然后再打开一个新页面,把系统地址再复制进去(效果:判断cookie直接进去主页)
这时我随便把一个页面注销(清除cookies)并且跳到登录页,然后切换到没点注销的那个页,里面权限操作都可以点,这时错误一大堆了,然后我想要的是里面任何请求,都要进行判断,然后我就用了IHttpModule 截取是截取到了,但是我把地址重定向,变成我请求的地址(比如后台的Index/xml_doc 的方法),变成请求context.Response.Redirect("/");//这个代表跳到登录页 
我页面上有个 弹出曾 单击弹出div 里面是iframe    ,然后弹出的iframe的地址变成  主页的地址,- -!,我要的是整个页面重定向到 登录页啊。而不是请求页改为登录页。
 
 private void Application_BeginRequest(Object source,
         EventArgs e)
    {
     
        // Create HttpApplication and HttpContext objects to access
        // request and response properties.
        HttpApplication application = (HttpApplication)source;
        HttpContext context = application.Context;      //  string s = context.Request.Url.ToString();
       
        string filePath = context.Request.FilePath;
        string fileExtension =
            VirtualPathUtility.GetExtension(filePath);        string path = Regex.Match(filePath, @"[Index]+").ToString();        if (path == "Index")
        {            if (Common.IsLogin() == false)  //判断用户是否登陆   ///大侠们看这边!!!!!
            {
                context.Response.End();  
                
                context.Response.Redirect("/");                
            }
            
        }
      
        //if (fileExtension.Equals("/Index/Index"))
        //{
        // //   string s = context.Request.Url.AbsolutePath.ToString();
        //    context.Response.Write("<h1><font color=red>" +
        //        "VerificationModule: Beginning of Request" +
        //        "</font></h1><hr>");
        //}
    }

解决方案 »

  1.   


    if (Common.IsLogin() == false)  //判断用户是否登陆   ///大侠们看这边!!!!!
                {
                    //context.Response.End();  //这句忽略
                    
                    context.Response.Redirect("/");                
                }
      

  2.   

    在Controller上面加[Authorize]特性,然后把配置文件里的<authentication mode="Forms">
    <forms loginUrl="~/Account/LogOn" timeout="2880"/>
    </authentication>指向你的登录页
      

  3.   

    asp.net mvc里应该用filter完成这个工作,不要写在Application_BeginRequest里
      

  4.   


    这个是一旦访问这个 加特性的Controller 会跳转到 登录页,“此网页包含重定向循环”
      

  5.   

    这个权限暂时没需要用到,现在只要 任意请求 都必须先跳到某个方法里面,判断cookies,如果cookies为空,我就跳转到 登录页,否则继续执行请求。
    就要这效果而已,刚刚看了很多filter 。好难理解呀~例子也下了个,看不大懂,正在费解
      

  6.   


    学习了一早上的Filter,结果还是一样啊,没cookies的时候我要整个页面跳转到登陆页,然后这个效果跟刚刚一样,直接把请求的地址替换成登录页- -,这个明显不行啊。filterContext.RequestContext.HttpContext.Response.Redirect("~/Login/LoginPage");
      

  7.   


    protected override bool AuthorizeCore(HttpContextBase httpContext)
            {
                string url = httpContext.Request.RawUrl;
                if (url.Equals("/") || url.Contains("/Home/LoginOn/") || url.Contains("/Home/CheckCode"))
                {
                    return true;
                }
                if (CC6UU_Admin.Commom.AdminInfo.Session == null)
                {
                    httpContext.Response.StatusCode = 404;
                    return false;
                }
                else
                {
                    return true;
                }
            }        public override void OnAuthorization(AuthorizationContext filterContext)
            {
                base.OnAuthorization(filterContext);
                if (filterContext.HttpContext.Response.StatusCode == 404)
                {
                    filterContext.Result = new RedirectResult("/");
                }
            }
      

  8.   


    ..一样哒。反正我就是在请求方法前  截取请求,然后这时不管怎么定向,效果等于把请求的地址换成登陆也地址。。谢谢各位了,结贴了
    我的解决办法是 ,直接先  clear 然后 end 直接不让用户看就是