IHttpModule实现SESSION过期时弹出登录框

 

一:xml配置:

<system.web>//------------这个节点下加

<httpModules>
            <add type="Zjwx.IHttpModuleFilter" name="IHttpModuleFilter" />

</httpModules>

</system.web>


 

二:ext-all-debug.js

  修改Ext.extend(Ext.data.Connection, Ext.util.Observable, {})里的handleResponse方法

        // private
        handleResponse: function(response) {
            this.transId = false;
            var options = response.argument.options;
            response.argument = options ? options.argument : null;
            if (response.responseText == "loginOvertime") {
                if (window.top && window.top.show_loginWindow) { window.top.show_loginWindow(); return; }
            }
            this.fireEvent(REQUESTCOMPLETE, this, response, options);
            if (options.success) {
                options.success.call(options.scope, response, options);
            }
            if (options.callback) {
                options.callback.call(options.scope, options, true, response);
            }
        },


 

三:后台代码;

using System;
using System.Collections.Generic;
using System.Web;


namespace Zjwx
{
    /// <summary>
    ///TestModule 的摘要说明
    /// </summary>
    public class IHttpModuleFilter : IHttpModule
    {
        public IHttpModuleFilter()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }


        private HttpApplication app = null;

        public void Init(HttpApplication application)
        {

            application.AcquireRequestState += (new EventHandler(this.Application_BeginRequest));

        }


        private void Application_BeginRequest(Object source, EventArgs e)
        {
            app = (HttpApplication)source;

            if (app.Context.Session != null)
            {
                string url = app.Context.Request.Url.AbsolutePath.ToLower();
                if (!url.Equals(app.Context.Request.ApplicationPath.ToLower() + "/default.aspx"))
                {
                    if (app.Context.Session[BLL.LoginUserBLL.sSessionKey] == null)
                    {
                        HttpResponse Response = app.Context.Response;
                        if (url.IndexOf(".aspx") > 0)
                        {
                            //show_loginWindow 参数1是同步,2是异步
                            Response.Write("<script>if(window.top&&window.top.show_loginWindow){window.top.show_loginWindow(1);}else{window.location.href='../../default.aspx';}</script>");
                            Response.End();
                        }
                        else if (url.IndexOf(".asmx") > 0)
                        {
                            Response.Write("loginOvertime");
                            Response.End();
                        }
                    }
                }
            }
        }


        public void Dispose()
        {

            if (null != app)
            {

                app.BeginRequest -= new EventHandler(Application_BeginRequest);

                app = null;

            }

        }


    }
}


阅读更多
个人分类: .net
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭