日期:2014-05-17  浏览次数:20417 次

IHttpModule 中AcquireRequestState下使用Session报未将对象设置引用到实例

public class UserAuthorizationModule : IHttpModule
    {
        public void Dispose() { }
        public void Init(HttpApplication context)
        {
            context.AcquireRequestState += new EventHandler(Application_AcquireRequestState);
        }

        public void Application_AcquireRequestState(object sender, EventArgs e)
        {
            HttpApplication application = sender as HttpApplication;;
            //HttpContext context = application.Context;
            HttpResponse response = application.Context.Response;
            Sys_Users Use = new Sys_Users();
            //获取当前请求的虚拟路径
            string Url = application.Context.Request.Path.ToString();

            switch (Url) 
            {
                case "/Web/index.htm":
                case "/Web/main.htm":
                case "/Web/menu.htm":
                case "/Web/header.htm":
                    if (application.Context.Session["Session_User"] == null)
                    {
                        application.Context.Response.Redirect("login.htm");
                        return;
                    }
                    break;
            }            
        }
    }

为什么在if (application.Context.Session["Session_User"] == null)这句的时候报未将对象设置引用到实例
session application AcquireRequestState

------解决方案--------------------
再继承下这个接口试试:I