利用全局应用程序文件禁止用户登录

 protected void Application_BeginRequest(object sender, EventArgs e)
        {
            if (System.Configuration.ConfigurationManager.AppSettings["hidecall"].ToString() != "true")
            {
                string url = Request.Url.ToString();
                string a = Request.PathInfo;
                if (url.IndexOf(".aspx") == -1)
                    return;
                string usernames = string.Empty;
                if (url.IndexOf("register.aspx") == -1 && url.IndexOf("login.aspx") == -1 && url.IndexOf("getpassword.aspx") == -1 && url.IndexOf("VerifyImagePage.aspx") == -1 && url.IndexOf("logout.aspx") == -1)
                {
                    string path = ("~/login.aspx");
                    if (Request.Cookies["dnt"] != null)
                    {
                        HttpCookie user = Request.Cookies["dnt"];
                        int uid = Convert.ToInt32(user["userid"]);
                        UserInfo usinfo = Users.GetUserInfo(uid);
                        if (usinfo != null)
                        {
                            usernames = usinfo.Username;
                            if (AdminUsers.GetUserId(usernames) <= 0)
                            {
                                Response.Redirect(path);
                            }
                        }
                        else
                        {
                            Response.Redirect(path);
                        }
                    }
                    else
                    {
                        Response.Redirect(path);
                    }
                }
            }
        }

posted on 2012-01-16 14:42  larryle  阅读(164)  评论(0)    收藏  举报