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;

            }

        }


    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值